注销表单在登录控件c#asp.net中出现空异常

注销表单在登录控件c#asp.net中出现空异常,c#,asp.net-mvc-3,security,login-control,C#,Asp.net Mvc 3,Security,Login Control,我正在使用mv3的websecurity登录。 我被这个问题困住了 我面临的错误是:- 对象引用未设置为对象的实例 这是我从你提供的细节中推断出来的。您的项目中有一个名为Shared\u Layout.cshtml的文件。在这个文件中,第36、37、38或39行有一个对象,您试图使用它,但没有先实例化它 现在,你怎么知道什么是空的呢。它也很简单。单击第36行并按F9。它将在应用程序中放置一个断点。现在按F5,它将启动调试过程。现在注销,调试器将在放置调试器的行停止。现在你可以看到什么是空的。你问

我正在使用mv3的websecurity登录。 我被这个问题困住了
我面临的错误是:- 对象引用未设置为对象的实例


这是我从你提供的细节中推断出来的。您的项目中有一个名为Shared\u Layout.cshtml的文件。在这个文件中,第36、37、38或39行有一个对象,您试图使用它,但没有先实例化它


现在,你怎么知道什么是空的呢。它也很简单。单击第36行并按F9。它将在应用程序中放置一个断点。现在按F5,它将启动调试过程。现在注销,调试器将在放置调试器的行停止。现在你可以看到什么是空的。

你问题中的一行写着:-

对象引用未设置为实例 NullReferenceException

当我们未能在代码中初始化引用类型并在之后尝试使用它时,会发生空引用异常。
外汇

List myList=null;
myList.Add(“Tom”);//这将引发空引用异常。
要正确地更正它,请在C#中初始化引用类型

List myList=newlist();
myList.Add(“Tom”)//编译并运行良好。

请不要在问题中添加“问候”一句,因为每个人都可以看到你的名字。这被认为是一种不好的做法。你没有必要发布完整的StackTrace并使问题令人毛骨悚然。我不同意,我发现毛骨悚然的问题更容易阅读,特别是在万圣节前后,我已经做过了。。一切都是正确的。。。但在结束括号之后。它给出了这个错误。。。还有,如果我对注销表发表意见。。它在my_布局页面的@RenderSection(“javascript”,required:false)处给出了相同的错误。。
     @Html.AntiForgeryToken()
Line 53:                                 <a href="javascript:document.getElementById('logoutForm').submit()" class="logout"></a>
Line 54:                             }
Line 55:                         </li>
Line 56:                     </ul>
    [HttpPost]
    [AllowAnonymous]
    [ValidateAntiForgeryToken]
    public ActionResult Login(LoginModel model, string returnUrl)
    {
        if (checkLogin(model.UserName))
        {
            if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
            {
                Session["UserID"] = WebSecurity.CurrentUserId.ToString();
                Session["UserName"] = WebSecurity.CurrentUserName.ToString();

                return RedirectToLocal(returnUrl);
            }
        }
        // If we got this far, something failed, redisplay form
        ModelState.AddModelError("", "The user name or password provided is incorrect.");
        return View(model);
    }

[HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult LogOff()
        {
            WebSecurity.Logout();
            System.Web.HttpContext.Current.Session.Clear();
            System.Web.HttpContext.Current.Session.Abandon();
            System.Web.HttpContext.Current.User = null;

            return RedirectToAction("Login", "Account");
        }
   List<string> myList = null ; 
   myList.Add("Tom") ; // This will throw a null reference exception.
  List<string> myList = new List<string> () ; 
  myList.Add("Tom") // compiles and runs fine.