MVC - 输入字符串的格式不正确 - Application_Error - Global.asax

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():

"Input string was not in a correct format "

堆栈跟踪:

 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 博客 (Link of blog) 中有浏览器链接的完整解释。我可以通过以下配置解决问题。

  <appSettings>
    <add key="vs:EnableBrowserLink" value="false"/>
  </appSettings>