public class CheckAdmin:Page
{
public CheckAdmin()
{
//bool isn = HttpContext.Current == null;//这里是false的
if (HttpContext.Current.Session["AdminId"] == null || HttpContext.Current.Session["AdminId"].ToString().Length <= 0)//这里报错“未将对象引用”,后面半句去掉也一直,
{
HttpContext.Current.Response.Write("<script>alert('你尚未登录,或登录超时!');location.href='~/login.aspx'</sciprt>");
}
}
}
实在想不通了,大家帮忙看看,在线等
解决方案 »
- 网站中使用AJAX的UpdatePanel无刷新,在本地调试运行正常,可是发布到服务器后就无法实现UpdatePanel无刷新
- “网页已过期,请重新登录系统”急!急!急!急!
- 刷新有时会出现未将对象引用到实例
- ajaxpro 调用 含有guid的参数方法时出现的情况
- ASP.NET 查询无响应
- 动态加载控件问题,高手请帮忙啊
- 一个关于window.open的问题请教
- 用IE直接打开PDF文件,屏蔽插件的工具条的求教
- 求助公文流转系统(Visual 2005 c#)开发!
- 开放FTP,欢迎大家上传下载!
- 怎么理解: <add verb="*" path="handler.aspx" type="HandlerExample.MyHttpHandler,HandlerTest"/>
- 文件上传到数据库中,怎么用下载工具下载
这样写也会一直报错?
{
HttpContext.Current.Response.Write("<script>alert('你尚未登录,或登录超时!');location.href='~/login.aspx'</sciprt>");
}
只有在配置文件或 Page 指令中将 enableSessionState 设置为 true 时,才能使用会话状态。还请确保在应用程序配置的 <configuration>\<system.web>\<httpModules> 节中包括 System.Web.SessionStateMod 或自定义会话状态模块。说明:这个网站是我在修改,以前是用session验证登录的,我现在想让直接继承这个类就行了,遇到如上问题,而且 我以前也这样做过,
在BasePage里
public class BasePage : System.Web.UI.Page
{
public BasePage()
{ }
protected override void OnInit(EventArgs O)
{
if (base.Session["UserId"] == null || base.Session["UserId"].ToString().Equals(""))
{
Response.Redirect("~/Error.aspx");
}
}
}
protected string GetVirtualPath()
{
string strServer = Convert.ToString(Request.ServerVariables["SERVER_NAME"]);
string strPort = Convert.ToString(Request.ServerVariables["SERVER_PORT"]);
string strRoot = Request.ApplicationPath;
if (strPort == "80")
strPort = "";
return string.Format("http://{0}{1}{2}/", strServer, strPort, strRoot);
}来源
http://blog.csdn.net/xuyingchunxyc/archive/2008/09/23/2970000.aspx
你先改web.config文件,把enableSessionState设置为true,然后只判断前半句
if (HttpContext.Current.Session["AdminId"] == null) 这样报的什么错?