error handling in asp.net MVC3
I have created an MVC3 application and added cutomerrors attribute on in web.config. It works in chrome and Firefox but When I run it in IE9, I get
The website cannot display the page
HTTP 500
Most likely causes: •The website is under maintenance. •The website has a programming error.
What you can try:
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=152368
开发者_运维百科 -->
<configuration>
<appSettings>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>
<system.web>
<customErrors mode="On"></customErrors>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages"/>
</namespaces>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
There is a known problem in Internet Explorer versions where a custom error page has to be at least 512 bytes. While this usually applies to old IE versions and usually resulting in a 404 error page, I'd recommend to ensure that your custom error page is, say 1 kB of size. You might put some HTML comments in or something. Just to ensure that it has nothing to do with that old IE bug.
Just one reference of many: http://perishablepress.com/press/2008/01/21/important-note-for-your-custom-error-pages/
That's the inbuilt IE error page. Can you post your web.config so we can see what you have in there?
<customErrors mode="On" defaultRedirect="/Home/Error">
<error statusCode="403" redirect="/Home/NoAccess" />
<error statusCode="404" redirect="/Home/NotFound" />
<error statusCode="500" redirect="/Home/Internal" />
</customErrors>
Is what I'd expect to see in the web config. I'm not sure what page is being shown in the other browsers.
I guess IE9 is expecting some content to be returned, try adding the Internal action and view to your home controller and specifying defaultRedirect="/Home/Internal" and see if that works.
精彩评论