[英]MVC - Input string was not in a correct format - Application_Error - Global.asax
我不知道在哪里拋出這個異常。 我攔截了 Application_Error 中的異常。 Application_Error 在頁面完全加載后調用。 它發生在任何頁面上。
Application_Error 代碼:
protected void Application_Error(object sender, EventArgs e)
{
string errorMessage = "";
LogServices logServ = new LogServices();
Exception exception = Server.GetLastError();
string exMsg = exception.Message;
Exception _ex = exception.InnerException;
while(null != _ex)
{
exMsg = string.Format("{0} {1}", exMsg, _ex.Message);
_ex = _ex.InnerException;
}
string logId = logServ.log(exception, "", Context.Request.UserAgent);
if (exMsg.IndexOf("was not found") != -1)
{
errorMessage = ElizeuSites.AssimEstaEscrito.Resources.Global.PageNotFound;
Server.ClearError();
string urlRedirect = String.Format("/FrontEnd/{0}/{1}?{2}={3}&errorMessage={4}", "Error", "PopUpError", "logId", logId, errorMessage);
Server.TransferRequest(urlRedirect);
}
}
捕獲錯誤 Server.GetLastError():
“輸入字符串的格式不正確”
堆棧跟蹤:
em System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args)
em System.String.Format(IFormatProvider provider, String format, Object[] args)
em Microsoft.VisualStudio.Web.PageInspector.Runtime.MappingData.MappingDataUtilities.GenerateSelectorIfUnique(List`1 elements, String selectorFormatString)
em Microsoft.VisualStudio.Web.PageInspector.Runtime.MappingData.MappingDataUtilities.GenerateSelectorsFromIds(List`1 elements, String selectorFormatString)
em Microsoft.VisualStudio.Web.PageInspector.Runtime.MappingData.MappingDataUtilities.GenerateSelectorsInternal(IEnumerable`1 elements, String selectorFormatString, Func`2 isUniqueTagName, Boolean indexAsLastResort)
em Microsoft.VisualStudio.Web.PageInspector.Runtime.MappingData.MappingDataUtilities.GenerateSelectors(IEnumerable`1 elements)
em Microsoft.VisualStudio.Web.PageInspector.Runtime.MappingData.MappingDataUtilities.ProcessDataIntoJsonObjects(IEnumerable`1 renderedOutputList)
em Microsoft.VisualStudio.Web.PageInspector.Runtime.Tracing.RequestDataHttpHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext context)
em System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
em System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
通過 Hakunamatata 的提示,我看到問題出在瀏覽器鏈接上。 在MSDN博客( 博客鏈接)里面有瀏覽器鏈接的完整說明。 我可以通過下面的配置解決問題。
<appSettings>
<add key="vs:EnableBrowserLink" value="false"/>
</appSettings>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.