ASP到ASP.NET会话变量
发布时间:2020-05-23 23:42:07 所属栏目: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-mvc – 如何编写自定义的RegularExpressionValidat
- asp.net-mvc – DisplayFormat未应用于十进制值
- asp.net – 在新的VS 2013 Identity UserManager中动态添加
- asp.net – 单元测试操作过滤器 – 如何模拟ViewResult
- asp.net – Visual Studio加载项自动附加到Development Ser
- asp.net – 什么是Html.AntiForgeryToken帮助函数?
- asp.net – Razor 3有什么新功能?
- ASP.NET Page_Init被解雇了两次!
- asp.net-mvc-4 – 提交相同的部分视图多次调用数据到控制器
- asp-classic – Request.BinaryRead(Request.TotalBytes)抛
推荐文章
站长推荐
- asp.net-mvc – 无法加载文件或程序集’Microsof
- asp.net-mvc – ASP.NET MVC – 从单个控制器动作
- asp.net – Wiki Content是否可移植?
- 压力测试ASP.Net应用程序
- asp.net-mvc-4 – MVC4 MEF插件和控制器命名空间
- asp.net-mvc – 从ASP MVC 3 Preview 1升级到bet
- asp.net-mvc – Url.Action映射Route属性的错误链
- asp.net-mvc – ASP.Net Html.DropDownList未选择
- 寻找一个使用Lucene.net与ASP.NET的例子
- Asp.net复选框和html数据属性
热点阅读
