【问题标题】:MVC - Input string was not in a correct format - Application_Error - Global.asaxMVC - 输入字符串的格式不正确 - Application_Error - Global.asax
【发布时间】:2015-09-07 22:41:40
【问题描述】:

我不知道这个异常是在哪里抛出的。 我在 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)

【问题讨论】:

  • logIderrorMessage的值是多少?
  • 尝试在/FrontEnd/之前添加~并检查logIderrorMessage
  • Application_Error中没有出现该错误。这段代码没问题。我只是截取了这个方法中的错误。问题是这个错误发生在系统某处,甚至调试我也找不到确切的位置。它可以是某个地方的 String.Format 。我认为它可能在 layout.cshtml 中,因为它发生在任何页面上。
  • 您可以在 Application_Error 中放置一个断点并尝试找出违规的 URL,然后调试该特定视图或部分视图。类似:technobird.blogspot.com.au/2010/09/…。这不是特定于您的错误,但您会明白的,
  • 你听说过CallStack吗?

标签: c# asp.net-mvc asp.net-mvc-4 global-asax application-error


【解决方案1】:

根据 Hakunamatata 的提示,我发现问题出在浏览器链接上。在 MSDN 博客(Link of blog) 里面有浏览器链接的完整解释。我可以通过下面的配置解决问题。

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

【讨论】:

    猜你喜欢
    • 2016-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-23
    • 2013-08-22
    相关资源
    最近更新 更多