我有ASP页面,我从查询字符串中获取值并在会话中存储。代码是
username = Trim(Request.querystring("username"))
Session("login")=username
NewUserName=Session("login")
现在我想在ASP.VB页面中访问此NewUsername值代码是(.aspx页)
<script type="text/javascript" language="javascript">
var login = '<%= Session["NewUserName"].ToString(); %>';
Session("login")=Login;
alert(login);
</script>
代码是(.aspx.vb)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Login = Session("login")
If Session("login") Is Nothing Then
Response.Redirect("../Default.aspx")
End If
Session("qid") = 0
End Sub
,但这给出了错误而无法访问值。
从ASP.NET页面上访问内存的经典Aspession可以制作的最简单的桥梁,就是这样的:
-
在ASP END上: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'll 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; } }