C# 未设置对象引用,无源行,错误源为tmp文件
当我尝试导航到已部署到生产机器的网站时,我收到以下错误C# 未设置对象引用,无源行,错误源为tmp文件,c#,asp.net,C#,Asp.net,当我尝试导航到已部署到生产机器的网站时,我收到以下错误 Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: Syst
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
[No relevant source lines]
Source File: c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\application portal\b63251b4\7eccc081\App_Web_t1vvgyvo.1.cs Line: 0
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
ASP._Page_Views_NewHire_NewEmpForm_cshtml.Execute() in c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\application portal\b63251b4\7eccc081\App_Web_t1vvgyvo.1.cs:0
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +279
System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +125
System.Web.WebPages.StartPage.ExecutePageHierarchy() +142
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +109
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +379
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +108
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +890
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +890
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +97
System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +241
System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +29
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +111
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +19
System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +51
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +111
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288
但是,这一个很好:
[Authorize]
[NewHireFilter]
public ActionResult ModuleOne()
{
ModuleOneViewModel vm = new ModuleOneViewModel();
HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value);
Int32 newHireID = Convert.ToInt32(ticket.Name);
vm.newHire = dbContext.Employees.FirstOrDefault(e => e.EmployeeID == newHireID);
return View(vm);
}
再一次,我非常感谢任何帮助,因为这对我来说是一个令人困惑的问题
谢谢。警告!您似乎正在数据库中以明文形式存储密码。这是一个严重的安全违规行为!密码不应该像那样存储。它们应该是单向散列和加密的,您应该比较散列形式的密码以确定有效性。看起来在视图的“编译版本”(NewHire\u NewEmpForm\u cshtml)中发生了异常。未设置某些对象实例。你能发布你所有的cshtml吗?当然可以;我已经为应该加载的视图添加了chtml。谢谢@mason的可能副本是一个很好的资源,但我不认为它有助于解决我的问题。我看到的最相关的数据是确保您实际上正在向视图传递模型。我是。此外,我还编辑了上面的代码,以说明非常相似的控制器/视图组合可以很好地工作。
[Authorize]
[NewHireFilter]
public ActionResult NewEmpForm()
{
HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value);
Int32 newHireID = Convert.ToInt32(ticket.Name);
Employee newEmp;
newEmp = dbContext.Employees.FirstOrDefault(e => e.EmployeeID == newHireID);
return View(newEmp);
}
[Authorize]
[NewHireFilter]
public ActionResult ModuleOne()
{
ModuleOneViewModel vm = new ModuleOneViewModel();
HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value);
Int32 newHireID = Convert.ToInt32(ticket.Name);
vm.newHire = dbContext.Employees.FirstOrDefault(e => e.EmployeeID == newHireID);
return View(vm);
}