Search code examples
aspnetboilerplate

Disabling multi-tenancy cause GetCurrentLoginInformationsOutput.User.get returned null


I am using ASP.NET MVC 5.X (Multi page and EF) to generate a solution, add some tables and entities, and then disable code first, at this time, things work.

Then I disable multi tenancy, but remove below line:

Configuration.MultiTenancy.IsEnabled = NxShufWebConsts.MultiTenancyEnabled;

Click F5, an exception (NullReferenceException) hit in the first line of GetShownLoginName method in SideBarUserAreaViewModel.cs file.

It says GetCurrentLoginInformationsOutput.User.get returne null.

Some callstack is as following:

ERROR 2018-08-10 23:39:14,217 [7    ] NxShufWeb.Web.Controllers.HomeController - 执行处理程序“System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper”的子请求时出错。
System.Web.HttpException (0x80004005): 执行处理程序“System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper”的子请求时出错。 ---> System.NullReferenceException: 未将对象引用设置到对象的实例。
   在 NxShufWeb.Web.Models.Layout.SideBarUserAreaViewModel.GetShownLoginName() 位置 D:\EnterWork\NxShufWeb\src\NxShufWeb.Web\Models\Layout\SideBarUserAreaViewModel.cs:行号 13
   在 ASP._Page_Views_Layout__SideBarUserArea_cshtml.Execute() 位置 d:\EnterWork\NxShufWeb\src\NxShufWeb.Web\Views\Layout\_SideBarUserArea.cshtml:行号 7
   在 System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
   在 System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
   在 System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
   在 System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
   在 System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
   在 System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)

Note: Because I disabled the code first, and delete the migration table, I did not run Update-Database again.

Any help?


Solution

  • delete all your website cookie from your browser. there might be some TenantId or UserId left over which is invalid