0

J'ai essayé d'implémenter la gestion des erreurs personnalisées dans ma démo MVC Application. Mais n'a pas fonctionné. Dans mon web.config j'ai l'entrée suivante pour CustomErrors et httpErrors:Comment travailler avec des pages d'erreur personnalisées dans ASP.NET MVC

Je commenté la section CustomErrors dans system.web

<?xml version="1.0" encoding="utf-8"?> 
<!-- 
    For more information on how to configure your ASP.NET application, please visit 
    http://go.microsoft.com/fwlink/?LinkId=169433 
    --> 
<configuration> 
    <configSections> 
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> 
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework" requirePermission="false" /> 
    <sectionGroup name="elmah"> 
     <section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" /> 
     <section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" /> 
     <section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" /> 
     <section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" /> 
    </sectionGroup></configSections> 
    <connectionStrings> 
    <add name="StudentContext" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-MvcApplication4;Integrated Security=true;Pooling=false" providerName="System.Data.SqlClient" /> 
    <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-MvcApplication7-20160206005617;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-MvcApplication7-20160206005617.mdf" providerName="System.Data.SqlClient" /> 
    </connectionStrings> 
    <appSettings> 
    <add key="webpages:Version" value="2.0.0.0" /> 
    <add key="webpages:Enabled" value="false" /> 
    <add key="PreserveLoginUrl" value="true" /> 
    <add key="ClientValidationEnabled" value="true" /> 
    <add key="UnobtrusiveJavaScriptEnabled" value="true" /> 
    </appSettings> 
    <system.web> 
    <customErrors mode="On" /> 
    <compilation debug="true" targetFramework="4.5" /> 
    <httpRuntime targetFramework="4.5" /> 
    <authentication mode="Forms"> 
     <forms loginUrl="~/Account/Login" 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.Optimization" /> 
     <add namespace="System.Web.Routing" /> 
     <add namespace="System.Web.WebPages" /> 
     </namespaces> 
    </pages> 
    <httpModules> 
     <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" /> 
     <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" /> 
     <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" /> 
    </httpModules></system.web> 
    <system.webServer> 
    <validation validateIntegratedModeConfiguration="false" /> 
    <handlers> 
     <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" /> 
     <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" /> 
     <remove name="ExtensionlessUrlHandler-Integrated-4.0" /> 
     <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" /> 
     <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" /> 
     <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /> 
    </handlers><modules> 
     <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" /> 
     <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" /> 
     <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" /> 
    </modules></system.webServer> 
    <runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
     <assemblyIdentity name="DotNetOpenAuth.Core" publicKeyToken="2780ccd10d57b246" /> 
     <bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="DotNetOpenAuth.AspNet" publicKeyToken="2780ccd10d57b246" /> 
     <bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="0.0.0.0-1.3.0.0" newVersion="1.3.0.0" /> 
     </dependentAssembly> 
    </assemblyBinding> 
    </runtime> 
    <entityFramework> 
    <contexts> 
     <context type="MvcApplication4.Context.StudentContext, MvcApplication4"> 
     <databaseInitializer type="MvcApplication4.Context.StudentEFInitializer, MvcApplication4" /> 
     </context> 
    </contexts> 
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /> 
    </entityFramework> 
<elmah> 
    <!-- 
     See http://code.google.com/p/elmah/wiki/SecuringErrorLogPages for 
     more information on remote access and securing ELMAH. 
    --> 
    <security allowRemoteAccess="false" /> 
    </elmah><location path="elmah.axd" inheritInChildApplications="false"> 
    <system.web> 
     <httpHandlers> 
     <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" /> 
     </httpHandlers> 
     <!-- 
     See http://code.google.com/p/elmah/wiki/SecuringErrorLogPages for 
     more information on using ASP.NET authorization securing ELMAH. 

     <authorization> 
     <allow roles="admin" /> 
     <deny users="*" /> 
     </authorization> 
     --> 
    </system.web> 
    <system.webServer> 
     <handlers> 
     <add name="ELMAH" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode" /> 
     </handlers> 
     <httpErrors errorMode="Custom" existingResponse="Replace"> 
     <clear/> 
     <!--<remove statusCode="404"/> 
     <remove statusCode="500"/>--> 
     <error statusCode="404" responseMode="File" path="/Error/page404.html"/> 
     <error statusCode="500" responseMode="File" path="/Error/page500.html"/> 
     </httpErrors> 
    </system.webServer> 
    </location></configuration> 

Et dans mes FilterConfig.cs I ont:

public class FilterConfig 
{ 
    public static void RegisterGlobalFilters(GlobalFilterCollection filters) 
    { 
     filters.Add(new HandleErrorAttribute()); 
    } 
} 

Voici mon fichier page400.html:

<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <title></title> 
</head> 
<body> 
    <h1>Page is not there dude !!</h1> 
    Sorry about this. 
</body> 
</html> 

sous le dossier d'erreur. Mais encore quand je frappe

http://localhost:49376/private/aaa 

(aaa méthode d'action n'est pas là) au lieu de la page d'erreur personnalisée, il me donne toujours la page d'erreur traditionnelle.

enter image description here

Voici ma capture d'écran Version IIS:

enter image description here

Mise à jour:

Je sais que la question semble un double d'un existant. Mais les réponses données ici ne résolvent pas mon problème. Je n'arrive toujours pas à voir la page d'erreur personnalisée 404.

+0

essayer '

+0

double possible de [Comment faire les pages d'erreur personnalisées fonctionnent dans ASP.NET MVC 4] (http://stackoverflow.com/questions/13905164/how-to-make-custom-error-pages-work-in-asp-net-mvc-4) – NightOwl888

+0

@ Alundrathedreamwalker .. n'a pas aidé :(Toujours obtenir la même erreur – StrugglingCoder

Répondre

1

Utiliser la configuration du serveur Web:

<system.webServer> 
    <httpErrors errorMode="Custom" existingResponse="Replace"> 
     <remove statusCode="404" /> 
     <error 
     statusCode="404" 
     path="/Error/page404.html" 
     responseMode="ExecuteURL" /> 
    </httpErrors> 
</system.webServer> 

Et ajoutez cette ligne à la méthode RegisterRoutes sur RouteConfig css:

routes.IgnoreRoute("Error/page404.html"); 
+0

Toujours pas de chance :( – StrugglingCoder

+0

Quelle version d'IIS Express est en cours d'exécution sur votre machine? httpErrors ne fonctionne pas sur IIS <7.0. Cette [entrée de blog] (https://dusted.codes/demystifying-aspnet-mvc-5-error-pages-and-error-logging) peut vous aider. – Balde

+0

Il est de 7,5. Je suis en train de mettre à jour ma question, y compris toutes les captures d'écran. Jetez un coup d'oeil s'il vous plait. – StrugglingCoder