简体   繁体   中英

ArgumentOutOfRangeException , IIS express on 2012 server

All of my controller actions are rendering fine except for one.

I have found other solutions that pertain to IIS express, however this is running on server 2012.

Here is the controller action:

public ActionResult Index()
    {

        try
        {
            var viewModels = GetHostInfoViewModelList();
            return View(viewModels);
        }
        catch (Exception ex)
        {
            ex.ReportError();
            return new HttpStatusCodeResult(404,$"{ex.Message}|{ex.InnerException}");

        }

    }

Here is GetHostInfoViewModelList:

  public IEnumerable<ViewModelHostInfo> GetHostInfoViewModelList()
    {
        using (var db = new WINCMUEntities())
        {
            try
            {
                //join host info with sleep status
                var sleepRecords = db.SleepTrackings.ToList();
                var hostInfo = db.WINCMU_HostInfo.ToList();
                var viewModels = new List<ViewModelHostInfo>();
                hostInfo.ForEach(x =>
                {
                    viewModels.Add(new ViewModelHostInfo()
                    {
                        HostName = x.HostName ?? "Not Found",
                        Id = x.ID,
                        newsystem = x.newsystem,
                        Zone = x.Zone ?? "Not Found",
                        IsSleeping = sleepRecords.FirstOrDefault(s => s.HostName.ToLower() == x.HostName.ToLower())
                                         ?.IsCurrentlySleeping ?? false,
                        IP_address = x.IP_address ?? "Not Found",
                        ReportingArea = x.ReportingArea ?? "Not Found",
                        agent_active = x.agent_active,
                        date_added = x.date_added,
                        is_agent = x.is_agent
                    });
                });

                return viewModels;
            }
            catch (Exception ex)
            {
                ex.ReportError();
                throw;
                //return new List<ViewModelHostInfo>();
            }
        }
    }

Here is the complete error text:

[ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: value] System.Web.HttpResponse.set_StatusDescription(String value) +4538824 System.Web.Mvc.HttpStatusCodeResult.ExecuteResult(ControllerContext context) +109 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList 1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +88 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList 1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +775 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList 1 filters, ActionResult actionResult) +81 System.Web.Mvc.Async.<>c__DisplayClass3_1.<BeginInvokeAction>b__5(IAsyncResult asyncResult) +188 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +38 System.Web.Mvc.<>c.<BeginExecuteCore>b__152_1(IAsyncResult asyncResult, ExecuteCoreState innerState) +26 System.Web.Mvc.Async.WrappedAsyncVoid 1 filters, ActionResult actionResult) +81 System.Web.Mvc.Async.<>c__DisplayClass3_1.<BeginInvokeAction>b__5(IAsyncResult asyncResult) +188 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +38 System.Web.Mvc.<>c.<BeginExecuteCore>b__152_1(IAsyncResult asyncResult, ExecuteCoreState innerState) +26 System.Web.Mvc.Async.WrappedAsyncVoid 1.CallEndDelegate(IAsyncResult asyncResult) +68 System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +52 System.Web.Mvc.Async.WrappedAsyncVoid 1.CallEndDelegate(IAsyncResult asyncResult) +39 System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +38 System.Web.Mvc.<>c.<BeginProcessRequest>b__20_1(IAsyncResult asyncResult, ProcessRequestState innerState) +40 System.Web.Mvc.Async.WrappedAsyncVoid 1.CallEndDelegate(IAsyncResult asyncResult) +68 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +38 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +602 System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +195 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +128

错误截图

The error message states that is while setting the response status that the exception occurs:

[ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: value] System.Web.HttpResponse.set_StatusDescription (String value) +4538824

Your code does not set the standard description for a 404 status result:

return new HttpStatusCodeResult(404,$"{ex.Message}|{ex.InnerException}");

Change this to:

return new HttpStatusCodeResult(404,"Not Found");

You can omit the description, but if you set it, it must match the status code.

This was self inflicted.

GetHostInfoViewModelList was throwing on the exception.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM