zoukankan      html  css  js  c++  java
  • Silverlight 实现session

    由于silverlight运行在客户端,我们只能模拟出session  首先定义一个SessionManager类

     
    using System;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Ink;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using System.Collections.Generic;
    
    namespace WebUPGIS.controls
    {
        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; }
            }
    
        }
    }
    
    再通过各种方式把asp.net的session传递给silverlight  例如
    1.通过请求页面 **.apsx?key=value 传给一个包含silverlight的页面 然后 在sl中获取
     
               IDictionary<String, String> paras = HtmlPage.Document.QueryString;
                if (paras.ContainsKey("userName"))
                {
                    this.button1.Content = paras["userName"];
                }
    2.如果包含silverlight的页面是aspx页面 可以先在页面后台的load中获取session 存放在hidden里面
     
     
    最后把session值保存到SessionManager中,例如
     
                HtmlDocument document = HtmlPage.Document;
                string hiddenStr = document.GetElementById("hiddenStr").GetAttribute("value");
                if(hiddenStr!="")
                {
                    string[] userInfo = hiddenStr.Split(';');
                    SessionManager.Session["userName"] = userInfo[0];
                    SessionManager.Session["userID"] = userInfo[1];
                }
    
                this.button1.Content = SessionManager.Session["userName"].ToString();
     
    在需要使用session的地方 用SessionManager.Session["sessionName"] 即可
    Powered By D&J (URL:http://www.cnblogs.com/Areas/)
  • 相关阅读:
    事务与事务隔离级别
    TNS12535: TNS: 操作超时
    11g的exp导出空表提示EXP00011: SCOTT.TEST1 不存在
    oracle中chr含义
    SQL Server 2008 System Views Map
    SQL Server Execution Plans eBook
    生成建表脚本(V3.0)
    SQL Server 2008 通过配置数据库邮件实现发送邮件功能
    MSSQL2005中的非公开存储过程sp_msdependencies
    SQL Server Tacklebox Free eBook
  • 原文地址:https://www.cnblogs.com/Areas/p/2154612.html
Copyright © 2011-2022 走看看