zoukankan      html  css  js  c++  java
  • 在Silverlight中使用SESSION

    首先Session是运行在服务器上的,而Silverlight运行在客户端。因此在Silverlight中使用SESSION的说法并不准确, 只因大家经常这样搜索才起这个名字。
     

    首先Session是运行在服务器上的,而Silverlight运行在客户端。因此在Silverlight中使用SESSION的说法并不准确,

    只因大家经常这样搜索才起这个名字。

     

    有两种方法实现Silverlight与Session的关联:

    方法一、通过WCF使用ASP.NET中的Session[因BasicHttpBinding不支持WCF中的Session,如使用WCF会话将报错 ]

      首先:在web.config中<system.serviceModel >下添加:

        <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>

      然后:在服务类[不是接口]下添加如下属性:

        [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

      接下来就可以使用Session记得添加System.Web的引用

        HttpContext.Current.Session["YourName"] = something;

        object something = HttpContext.Current.Session["YourName"];

     

    方法二、在客户端新建一个静态类模拟Session

      如要保存登陆信息,可在验证了用户名、密码之后在客户端保存相关信息。

    using System;
    using System.Collections.Generic;
    
    namespace SessionDemo
    {
        public static class SessionManager
        {
            private static Dictionary<string, object> session = new Dictionary<string, object>();
    
            public static Dictionary<string, object> Session
            {
                get { return SessionManager.session; }
                set { SessionManager.session = value; }
            }
        }
    }
    

     使用方法:

    赋值:
    SessionManager.Session["uname"] = "kunal";
    
    取值:
    txbUname.Text = SessionManager.Session["uname"].ToString();
    
  • 相关阅读:
    牛客 小乐乐和25
    codeforces 1303 D 二进制瞎搞
    codeforces 1307 D 最短路bz+贪心
    codeforces 1316 C math
    codeforces 1328E LCA
    codeforces 1335 E2 思维
    codeforces 1335 E1 思维
    codeforces 1342 D 贪心+后缀和
    codeforces 1348D (思维+贪心)
    codeforces 1362 E 进制的性质
  • 原文地址:https://www.cnblogs.com/yuhanzhong/p/3259652.html
Copyright © 2011-2022 走看看