我有一个旧系统,而不是由我开发的经典ASP系统。 我有一个由ASP.NET开发的新系统
如何将会话变量(不是复杂的类型,只是一个简单的字符串或int)传递给那个经典的ASP页面?我不需要任何回复。
要为作品添加扳手 - 如果经典ASP网站位于不同的域中,如何进行“切换”或转移?
更新: 不能使用通过查询字符串传递项目或将其存储在数据库中并让经典ASP从数据库中读取它的选项。
谢谢
答案 0 :(得分:0)
您可以使用经典的asp页面来设置会话变量。发布参数。
然后从你的asp.net页面调用那个经典的asp页面。
示例(未完成)session.asp:
if session("userIsloggedIn") = true and request.form("act") = "setSessionVar" then
session(request.form("name")) = request.form("value")
end if
当然这是某种黑客,但我们谈的是经典的asp ......
答案 1 :(得分:0)
我的方向不同。我通过cookie交换了会话状态。添加这些方法。所以现在我不是直接调用Session,而是使用这些方法。
ASP.NET
public static void AddSessionCookie(string key, string value)
{
var cookie = HttpContext.Current.Request.Cookies["SessionCookie"];
if (cookie == null)
{
cookie = new HttpCookie("SessionCookie");
cookie.Expires = DateTime.Now.AddHours(12);
HttpContext.Current.Response.Cookies.Add(cookie);
HttpContext.Current.Request.Cookies.Add(cookie);
}
HttpContext.Current.Session[key] = value;
cookie[key] = value;
}
public static string GetSessionCookie(string key)
{
if (HttpContext.Current.Session[key] == null)
return string.Empty;
string cook = HttpContext.Current.Session[key].ToString();
if (!String.IsNullOrEmpty(cook))
{
var cookie = HttpContext.Current.Request.Cookies["SessionCookie"];
if (cookie == null)
{
cookie = new HttpCookie("SessionCookie");
cookie.Expires = DateTime.Now.AddHours(12);
HttpContext.Current.Response.Cookies.Add(cookie);
HttpContext.Current.Request.Cookies.Add(cookie);
}
if (cookie != null)
cookie[key] = cook;
return cook;
}
return cook;
}
然后是经典
Function AddSessionCookie(key, value)
Response.Cookies("SessionCookie")(key)= value
Response.Cookies("SessionCookie").Expires = DATE + 1
Session(key) = value
End Function
Function GetSessionCookie(key)
If Session(key) <> "" Then
Response.Write(Session(key))
ELSEIF Response.Cookies("SessionCookie")(key) <> "" THEN
Session(key)=Response.Cookies("SessionCookie")(key)
Set GetSessionCookie = Session(key)
End If
End Function