private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
string userclass;
userclass=(string)Session["userclass"];
ClassName.Text="请输入分类名";
if(userclass.Trim()=="系统管理员")
{
getClass();
}
else
{
Page.Visible=false;
}
}
// 在此处放置用户代码以初始化页面
}
堆栈跟踪:
[NullReferenceException: 未将对象引用设置到对象的实例。]
news1.admin.admin_class.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\news1\admin\admin_class.aspx.cs:49
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
{
if(!Page.IsPostBack)
{
string userclass;
userclass=(string)Session["userclass"];
ClassName.Text="请输入分类名";
if(userclass.Trim()=="系统管理员")
{
getClass();
}
else
{
Page.Visible=false;
}
}
// 在此处放置用户代码以初始化页面
}
堆栈跟踪:
[NullReferenceException: 未将对象引用设置到对象的实例。]
news1.admin.admin_class.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\news1\admin\admin_class.aspx.cs:49
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
解决方案 »
- 调试用VS2005做的项目时,关闭了winform窗口了,但是VS2005仍在运行。这是什么问题?
- list<T>的概念问题
- 怎样实现treeview的节点实现richtextBox内所输入的文字变换粗体的功能?(VS2005 WINFORM)
- 来谈谈【权限模块】的设计~~~
- 求教 变量作用域的问题
- 大家一般使用什么测试工具
- 用 HttpWebRequest 访问 SSL 网页的问题
- 面向過程編程和面向對象編程的各自特點和異同
- c#学了好久 可是现在要做项目了一点头绪都没有 请教各位高手!!
- windows forms 无法捕获回车键
- 通过Process.Start("mytest.exe","1")给mytest.exe传递参数1 ,要怎么写mytest.exe里面的代码?
- 文件名无效,请检查数据库的文件名
(string)Session["userclass"]当为null时结果还是null解决:
用if(userclass!=null && userclass.Trim()=="系统管理员")
if(!string.isNullOrEmpty(userclass) && userclass.Trim()=="系统管理员")
{
getClass();
}
else
{
Page.Visible=false;
}
你传过来的Session["userclass"]的值为null,所以会报错加条件:
if(userclass!=null && userclass.Trim()=="系统管理员")
{
//..操作.
}
测试下 你的Session 先.
{
...............
}
else
{}
private void Page_Load(object sender, System.EventArgs e)
{ if(!Page.IsPostBack)
{ string userclass;
if(Session["userclass"]!=null)
{
userclass=(string)Session["userclass"];
ClassName.Text="请输入分类名";
if(userclass.Trim()=="系统管理员")
{
getClass();
}
else
{
Page.Visible=false;
}
}
}// 在此处放置用户代码以初始化页面
}
请各位帮帮忙
if(userAddPower((int)Session["addnews"],(int)Session["addnchk"],(string)Session["userclass"])) {
Literal1.Text="<a href='admin_articleAdd.aspx' target='right'>添加新闻</a>";
Literal1.Text+="|"+"<a href='admin_article.aspx' target='right'>新闻管理</a>";
}
else
{
Literal1.Text="<a href='admin_articleAdd.aspx' target='right'>添加新闻</a>";
}
if(validateUserClass((string)Session["userclass"])) {
Literal2.Text="<a href='admin_check.aspx' target='right'>新闻审核</a>";
Literal2.Text+="|"+"<a href='admin_move.aspx' target='right'>转移新闻</a>";
}
if(validateUserClass((string)Session["userclass"]))
{
Literal3.Text="<a href='admin_class.aspx' target='right'>进入分类管理</a>";
}
if(validateUserClass((string)Session["userclass"])) {
Literal4.Text = "<a href='admin_useradd.aspx' target='right'>添加用户</a>";
Literal4.Text+= "|"+"<a href='admin_user.aspx' target='right'>用户管理</a>";
Literal5.Text = "<a href='admin_change.aspx' target='right'>更改账号</a>";
}
else
{
Literal4.Text="<a href='admin_change.aspx' target='right'>更改账号</a>";
}
if (validateUserClass((string)Session["userclass"]))
{
Literal6.Text="<a href='admin_upfiles.aspx' target='right'>管理上传文件</a>";
}
}
Session["addnchk"]=1;
Session["userclass"]="系统管理员";