zoukankan      html  css  js  c++  java
  • 在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<stringobject> session = new Dictionary<stringobject>();

            
    public static Dictionary<stringobject> Session
            {
                
    get { return SessionManager.session; }
                
    set { SessionManager.session = value; }
            }
        }
    }

    使用方法:

    赋值:
    SessionManager.Session[
    "uname"= "kunal";

    取值:
    txbUname.Text 
    = SessionManager.Session["uname"].ToString();

    参考信息:http://forums.silverlight.net/forums/t/23080.aspx

  • 相关阅读:
    收藏:iBLC编码器
    蛙蛙推荐:怎样调试asp.net黄页错
    蛙蛙推荐:IE下3px bug研究
    蛙蛙推荐:winform入门
    蛙蛙推荐:蛙蛙牌云存储服务
    整理:个人知识管理相关链接
    蛙蛙推荐:c#编写网络电话
    蛙蛙推荐:蛙蛙教你解析网络包
    有用的SQL 语句(转) dodo
    .net 点击刷新验证码问题 dodo
  • 原文地址:https://www.cnblogs.com/zcy_soft/p/1798417.html
Copyright © 2011-2022 走看看