[英]ArgumentOutOfRangeException , IIS express on 2012 server
除了一個之外,我的所有控制器動作都呈現良好。
我找到了與 IIS express 相關的其他解決方案,但是這是在服務器 2012 上運行的。
這是控制器操作:
public ActionResult Index()
{
try
{
var viewModels = GetHostInfoViewModelList();
return View(viewModels);
}
catch (Exception ex)
{
ex.ReportError();
return new HttpStatusCodeResult(404,$"{ex.Message}|{ex.InnerException}");
}
}
這是 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>();
}
}
}
這是完整的錯誤文本:
[ArgumentOutOfRangeException:指定的參數超出了有效值的范圍。 參數名稱:值] 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 過濾器, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +775 System.Web.Mvc.ControllerActionConokeInvokerWithFilterInvController 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
錯誤消息指出,在設置發生異常的響應狀態時:
[ArgumentOutOfRangeException:指定的參數超出了有效值的范圍。 參數名稱:值]
System.Web.HttpResponse.set_StatusDescription
(字符串值)+4538824
您的代碼沒有為 404 狀態結果設置標准描述:
return new HttpStatusCodeResult(404,$"{ex.Message}|{ex.InnerException}");
將此更改為:
return new HttpStatusCodeResult(404,"Not Found");
您可以省略描述,但如果您設置了它,它必須與狀態代碼匹配。
這是自己造成的。
GetHostInfoViewModelList 拋出異常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.