Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Said Article.Mobile 和 Article 页面偶尔报 System.NullReferenceException #12

Closed
linkFly6 opened this issue Jan 15, 2017 · 1 comment
Labels

Comments

@linkFly6
Copy link
Owner

System.NullReferenceException: 未将对象引用设置到对象的实例。
   在 ASP._Page_Views_Said_Article_cshtml.Execute() 位置 Said\Article.cshtml:行号 8
   在 System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
   在 System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
   在 System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
   在 System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
   在 System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1a.<InvokeActionResultWithFilters>b__17()
   在 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
   在 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
   在 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult)
   在 System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult)

查了下问题大概集中在这几个地方:

  • Article.cshtml : 行号 8
  • Said.Application.UserApplication.Add(User model)
  • 在 Said.Common.SaidRecordCommon.GetUserId(HttpContext context, Boolean noCache)
  • Article.Mobile.cshtml
@linkFly6
Copy link
Owner Author

linkFly6 commented Jan 20, 2017

问题是因为 Said 使用了 Entity framework,而在 Web Application 中使用了静态化的 DbContext(单例)。
而 Web 中,每个 Request 都是一个单独的线程,EF 的 DbContext 应该是每个线程占用一个实例,而不是所有的线程都占用一个 DbContext。
所以导致了各种数据错乱的异常,在 这次提交中重新修正了底层和逻辑层的逻辑

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant