不加if (Session["MyForbid"] != null)这一句,
提示未将对象引用设置到对象的实例,加上提示当前上下文不存在名称“MyForbidString”public partial class System_CompanyForm : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       if (Session["MyForbid"] != null)
     {
            string MyForbidString = Session["MyForbid"].ToString();
  }
  if (MyForbidString.IndexOf("E2") > 1)
  {
      Server.Transfer("~/SystemManage/AllErrorHelp.aspx");
  }
    }
错误1 当前上下文中不存在名称“MyForbidString”(红色的)麻烦高手帮忙看看,O(∩_∩)O谢谢

解决方案 »

  1.   


    if (Session["MyForbid"] != null)
         {
                string MyForbidString = Session["MyForbid"].ToString();
      }
    改成
    string MyForbidString
    if (Session["MyForbid"] != null)
         {
                MyForbidString = Session["MyForbid"].ToString();
      }
      

  2.   

           if (Session["MyForbid"] != null)
         {
                string MyForbidString = Session["MyForbid"].ToString();
    if (MyForbidString.IndexOf("E2") > 1)
      {
          Server.Transfer("~/SystemManage/AllErrorHelp.aspx");
      }
      }
      
      

  3.   

    public partial class System_CompanyForm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           if (Session["MyForbid"] != null)
           {
                string MyForbidString = Session["MyForbid"].ToString();
      
               if (MyForbidString.IndexOf("E2") > 1)
               {
                     Server.Transfer("~/SystemManage/AllErrorHelp.aspx");
               }
        }