ASP到ASP.NET会话变量
发布时间:2020-12-15 23:54:31 所属栏目:asp.Net 来源:网络整理
导读:我们有一个经典asp的网站,我们正在慢慢迁移到ASP.NET. 问题当然是经典的asp和ASP.NET如何处理Sessions.在花了最后几个小时研究网络后,我发现了很多文章,但没有一篇文章比其他文章更突出. 是否有最佳实践将会话变量传递给经典的asp和asp.net?安全是必须的,并
我们有一个经典asp的网站,我们正在慢慢迁移到ASP.NET.
问题当然是经典的asp和ASP.NET如何处理Sessions.在花了最后几个小时研究网络后,我发现了很多文章,但没有一篇文章比其他文章更突出. 是否有最佳实践将会话变量传递给经典的asp和asp.net?安全是必须的,并且非常感谢任何带有示例的解释. 解决方法
将经典asp中的单个会话变量传递给.net服务器端(从客户端隐藏会话值)的简单桥接器将是:
>在ASP端:输出会话的asp页面,例如调用它asp2netbridge.asp <% 'Make sure it can be only called from local server ' if (request.servervariables("LOCAL_ADDR") = request.servervariables("REMOTE_ADDR")) then if (Request.QueryString("sessVar") <> "") then response.write Session(Request.QueryString("sessVar")) end if end if %> >在.net端,远程调用该asp页面. : private static string GetAspSession(string sessionValue) { HttpWebRequest _myRequest = (HttpWebRequest)WebRequest.Create(new Uri("http://yourdomain.com/asp2netbridge.asp?sessVar=" + sessionValue)); _myRequest.ContentType = "text/html"; _myRequest.Credentials = CredentialCache.DefaultCredentials; if (_myRequest.CookieContainer == null) _myRequest.CookieContainer = new CookieContainer(); foreach (string cookieKey in HttpContext.Current.Request.Cookies.Keys) { ' it is absolutely necessary to pass the ASPSESSIONID cookie or you will start a new session ! ' if (cookieKey.StartsWith("ASPSESSIONID")) { HttpCookie cookie = HttpContext.Current.Request.Cookies[cookieKey.ToString()]; _myRequest.CookieContainer.Add(new Cookie(cookie.Name,cookie.Value,cookie.Path,string.IsNullOrEmpty(cookie.Domain) ? HttpContext.Current.Request.Url.Host : cookie.Domain)); } } try { HttpWebResponse _myWebResponse = (HttpWebResponse)_myRequest.GetResponse(); StreamReader sr = new StreamReader(_myWebResponse.GetResponseStream()); return sr.ReadToEnd(); } catch (WebException we) { return we.Message; } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – IdentitySever3重定向多个域的URL
- asp.net-mvc – 从DataAnnotation类中渲染LabelFor无标签标
- asp.net – CLSID为{00024500-0000-0000-C000-000000000046
- asp.net-mvc – ASP.NET MVC Metro Style
- asp.net core后台系统登录的快速构建
- asp.net-mvc – 如何构建通用存储库
- asp.net – System.Byte []在gridview中显示而不是图像?
- asp.net – 以编程方式将HTML转换为Markdown语法
- asp.net – 是否值得在IIS7中启用动态压缩?
- ASP.NET Core集成现有系统认证
推荐文章
站长推荐
热点阅读