zoukankan      html  css  js  c++  java
  • Cookieless Session In WebService

    protected void Button1_Click(object sender, EventArgs e)
    {
        localhost.MyDemo MyService;
    
        // try to get the proxy from Session state
        MyService = Session["MyService"] as localhost.MyDemo;
    
        if (MyService == null)
        {
            // create the proxy
            MyService = new localhost.MyDemo();
     
            // create a container for the SessionID cookie
            MyService.CookieContainer = new CookieContainer();
     
            // store it in Session for next usage
            Session["MyService"] = MyService;
        }
    
        // call the Web Service function
        Label1.Text += MyService.HelloWorld() + "<br />";
    }
    

      

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.SessionState;
    
    namespace TestWebServiceTradition.WS
    {
        public class OurSessionIDManager : ISessionIDManager
        {
            public OurSessionIDManager() { }
    
            private SessionIDManager sid = new SessionIDManager();
    
            public string CreateSessionID(HttpContext context)
            {
                return sid.CreateSessionID(context);
            }
            public string GetSessionID(HttpContext context)
            {
                return sid.GetSessionID(context);
            }
            public void Initialize()
            {
                sid.Initialize();
            }
            public bool InitializeRequest(HttpContext context, bool suppressAutoDetectRedirect, out bool supportSessionIDReissue)
            {
                bool redirectCookie = false;
                if ((context.Request.RawUrl.ToLower().IndexOf(".asmx") > -1))
                    redirectCookie = true; 
                return sid.InitializeRequest(context, redirectCookie, out supportSessionIDReissue);
            }
            public void RemoveSessionID(HttpContext context)
            {
                sid.RemoveSessionID(context);
            }
            public void SaveSessionID(HttpContext context, string id, out bool redirected, out bool cookieAdded)
            {
                sid.SaveSessionID(context, id, out redirected, out cookieAdded);
            }
            public bool Validate(string id)
            {
                return sid.Validate(id);
            }
        }
    }
    

      

    <configuration>
       
    <system.web>
       
    <webServices>
           
    <protocols>
               
    <addname="HttpGet"/>
               
    <addname="HttpPost"/>
           
    </protocols>
       
    </webServices>
       
    </system.web>
    </configuration>
  • 相关阅读:
    requets中urlencode的问题
    洛谷$P4503 [CTSC2014]$企鹅$QQ$ 哈希
    洛谷$P5446 [THUPC2018]$绿绿和串串 $manacher$
    洛谷$P5329 [SNOI2019]$字符串 字符串
    洛谷$P1390$ 公约数的和 欧拉函数
    洛谷$P4318$ 完全平方数 容斥+二分
    入门懵逼钨丝繁衍
    $ CometOJ-Contest#11 D$ $Kruscal$重构树
    洛谷$P4884$ 多少个1? 数论
    入门数论简单总结
  • 原文地址:https://www.cnblogs.com/wucg/p/2425184.html
Copyright © 2011-2022 走看看