未设置对象引用,没有源LInes,错误源是tmp文件

时间:2017-02-21 19:08:37

标签: 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: 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

现在基本错误(对象引用未设置..)是我以前遇到过的。令我难过的是“没有相关的源代码行”以及错误的源文件是临时的。

我非常感谢有关问题的建议。

以下编辑

应加载的视图:

   @model Application_Portal.Models.Employee


<h2> New Employee Data Information</h2>


<form class="form-horizontal" method="post" id='newHireForm' action="NewEmpForm">


    <input type="hidden" name="EmployeeID" value="@Model.EmployeeID" />

    <div class="form-group">
        <label class="control-label col-md-2">First Name: </label><div class='col-md-4'><input type='text' class='form-control' readonly value='@Model.FirstName' /></div>
        <label class="control-label col-md-2">Last Name: </label><div class='col-md-4'><input type='text' class='form-control' readonly value='@Model.LastName' /></div>
    </div>

    <div class="form-group">
        <label class="control-label col-md-2">Full SSN: </label><div class='col-md-4'><input type='password' class='form-control' name="SSN" id="SSN" /></div>
        <label class="control-label col-md-2">Confirm SSN: </label><div class='col-md-4'><input type='password' class='form-control' id="SSNConfirm" /></div>
    </div>

    <div class="form-group">
        <label class="control-label col-md-2">Date of Birth: </label><div class='col-md-4'><input type='text' class='form-control' name="DOB" /></div>
    </div>

    <div class="form-group">
        <label class="control-label col-md-2">Phone: </label><div class='col-md-4'><input type='text' class='form-control' readonly value='@Model.Phone' /></div>
        <label class="control-label col-md-2">Cell Phone: </label><div class='col-md-4'><input type='text' class='form-control' readonly value='@Model.CellPhone' /></div>
    </div>
    <div class="form-group">
        <label class="control-label col-md-2">Street Address: </label><div class='col-md-4'><input type='text' class='form-control' readonly value='@Model.StreetAddress' /></div>
        <label class="control-label col-md-2">City: </label><div class='col-md-4'><input type='text' class='form-control' readonly value='@Model.Applicant.City' /></div>
    </div>

    <div class="form-group">
        <label class="control-label col-md-2">State: </label><div class='col-md-4'><input type='text' class='form-control' readonly value='@Model.Applicant.State' /></div>
        <label class="control-label col-md-2">Zip: </label><div class='col-md-4'><input type='text' class='form-control' readonly value='@Model.Applicant.Zip' /></div>
    </div>

    <div class="form-group">
        <label class="control-label col-md-2">Marital Status: </label><div class='col-md-4'><input type='text' class='form-control' name="MaritalStatus" /></div>
        <label class="control-label col-md-2">Gender: </label><div class='col-md-4'><select class='form-control' name="Sex"><option value="M">Male</option><option value="F">Female</option></select></div>
    </div>


    <div class="form-group">
        <label class="control-label col-md-2">Race: </label><div class="col-md-4">
            <select class='form-control' name='Race'>
                <option value="White">White</option>
                <option value="Black">Black</option>
                <option value="Hispanic">Hispanic</option>
                <option value="Asian">Asian or Pacific Islander</option>
                <option value="Native">American Indian or Alaskan Native</option>
            </select>
        </div>
        <label class="control-label col-md-2">Residency: </label><div class='col-md-4'><select class='form-control' name="Residency"><option value="Citizen">Citizen or National of the United States</option><option value="Lawful Permanent Resident">Lawful Permanent Resident</option><option value='Authorized Alien'>Authorized Alien</option></select></div>
    </div>
    <div class="form-group">
        <label class="control-label col-md-2">Alien # or Admission # (optional): </label><div class="col-md-4">
            <input type="text" class='form-control' name='AlienNumber' />
        </div>
    </div>
    <input type="submit" value="Submit" name="applicationSubmit" id="applicationSubmit" class="btn btn-primary pull-right" />

</form>

这是给我带来麻烦的控制器/视图组合:

    [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);
    }

同样,我真的很感激任何帮助,因为这对我来说是一个令人困惑的问题。

感谢。

0 个答案:

没有答案