你如session存储的是用户id,你可以改为使用cookie来存储id//登陆成功设置cookie Response.Cookies.Add(new HttpCookie("userid", "用户id的值")); if (Request.Cookies["userid"] == null ) { Response.Write("没路登陆系统!");Response.End()}if request.Cookies("userid")="" then response.Write "没路登陆系统!" end if
cookie 是记录到本地的。。 但有的电脑禁用了。。 百度cookie用法一大堆。。
共用方法http://msdn.microsoft.com/zh-cn/library/aa479313.aspx 如何在传统 ASP 和 ASP.NET 之间共享会话状态
Response.Cookies.Add(new HttpCookie("userid", "用户id的值")); if (Request.Cookies["userid"] == null )
{ Response.Write("没路登陆系统!");Response.End()}if request.Cookies("userid")="" then
response.Write "没路登陆系统!"
end if
如何在传统 ASP 和 ASP.NET 之间共享会话状态
asp.net 是可以在数据库里保存的
<%
Response.Cookies("snames")="您好!"
%>
<%
fname=Request.Cookies("snames")
Response.Write(fname)
%>
<html>
<head>
<title></title>
</head>
<body>
</body>
</html>
在asp.net中写的代码如下:
Encoding gb2312 = Encoding.GetEncoding("gb2312");
string fname = Request.Cookies["snames"].Value;
//lbl.Text = HttpUtility.UrlDecode(fname, Encoding.UTF8);
lbl.Text = HttpUtility.UrlDecode(fname, gb2312);
这样只是在我打开asp页面后,在打开asp.net才能显示出“您好!”这几个字,如果只是单独的打开asp.net,有时能显示出“您好!”,有时则显示“未将对象引用设置到对象的示例”,这是怎么回事?显示的内容具体如下:
“/”应用程序中的服务器错误。
--------------------------------------------------------------------------------未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误:
行 12: {
行 13: Encoding gb2312 = Encoding.GetEncoding("gb2312");
行 14: string fname = Request.Cookies["snames"].Value;
行 15: //lbl.Text = HttpUtility.UrlDecode(fname, Encoding.UTF8);
行 16: lbl.Text = HttpUtility.UrlDecode(fname, gb2312);
源文件: d:\aspasp.net\Default.aspx.cs 行: 14 堆栈跟踪:
[NullReferenceException: 未将对象引用设置到对象的实例。]
_Default.Page_Load(Object sender, EventArgs e) in d:\aspasp.net\Default.aspx.cs:14
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207
--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:4.0.30319; ASP.NET 版本:4.0.30319.272