我有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
但是这会产生错误而不会访问该值。
答案 0 :(得分:0)
您可以从asp.net页面访问内存中的Classic ASPSESSION的最简单的桥接器是:
在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'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;
}
}