Base solution for your next web application

Activities of "devkev2403"

I have my preferred solution now.

I set customErrors off, and in httpErrors I was missing the existingResponse attribute. So now I use this:

<system.webServer>
  <system.webServer>
    <httpErrors errorMode="Custom" existingResponse="Replace" defaultResponseMode="File">
      <remove statusCode="400"/>
      <remove statusCode="401"/>
      <remove statusCode="402"/>
      <remove statusCode="403"/>
      <remove statusCode="404"/>
      <remove statusCode="405"/>
      <remove statusCode="406"/>
      <error statusCode="400" path="Errors\400.html" />
      <error statusCode="401" path="Errors\401.html" />
      <error statusCode="402" path="Errors\402.html" />
      <error statusCode="403" path="Errors\403.html" />
      <error statusCode="404" path="Errors\404.html" />
      <error statusCode="405" path="Errors\405.html" />
      <error statusCode="406" path="Errors\406.html" />
  </httpErrors>
</system.webServer>

This works well, but I can not find where the text for other errors come from. For example, if I get a 501, I don't get the default IIS 501 page in full but I do get the appropriate 501 error message.

HI ismcagdas,

turning customErrors off seems like cheating.

I want ASP.NET to handle errors for requests that enter the and then fail in the ASP.NET pipeline.

I want IIS to handle errors for requeests that do not enter the ASP.NET pipeline e.g. static files that are missing so give a 404.

  1. Why do requests for static files e.g. <a class="postlink" href="http://www.abpzerosite.com/image.jpg">http://www.abpzerosite.com/image.jpg</a> enter theASP.NET pipeline - I can't find any routing configuration for this in the source?

  2. Turning customErrors off does not actually seem to work. I am investigating this now. Is that because of this code:

context.HttpContext.Response.TrySkipIisCustomErrors = true;

Hi alper,

thank you for your reply but I don't think your solution applies to me as I am not using ASP.NET Core.

I am trying to implement custom error pages but think in the BoilerPlate Framework (MVC5/jQuery MPA) ASP.NET is handling static file requests.

For example, if I specify ASP.NET custom errors in web.config:

<customErrors mode="On" redirectMode="ResponseRewrite">
  <error statusCode="404" redirect="/Errors/404.aspx"/>
</customErrors>

and visit a controller that does not exist, my.website.com/nullcontroller/nullaction, I correctly get the ASP.NET 404 page 404.aspx.

Now, I can also configure IIS custom errors in web.config:

<system.webServer>
	
	<httpErrors errorMode="Custom">  
		<remove statusCode="404"/>
		<error statusCode="404" path="Errors\404.html" responseMode="File"/>
	</httpErrors>
  </system.webServer>

However now, if I visit a non-existing page like my.website.com/notexist.html I still get the ASP.NET 404.aspx error page, not the IIS 404.html error page. ASP.NET is trying to server the static file and can't find it so returns the ASP.NET 404 page. Normally IIS would handle the static file request and use the IIS 404 page.

I prove this to myself by modifying the routes in RouteConfig.cs and adding a route to explicitly ignore the notexist.html static file.

public static void RegisterRoutes(RouteCollection routes)
{
  routes.IgnoreRoute("notexist.html");  // My test URL
  routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
  ...
  ...

Now if I visit my.website.com/notexist I get the intended page, the IIS 404.html error page. ASP.NET did not attempt to handle the static file request. Instead IIS attempted to find the file and failed so served it's 404 page.

I am just wondering, how is BoilerPlate configured (e.g. where in the code/config) such that html files are handled by ASP.NET and not IIS. By default, in the sample Visual Studio MVC application, static files are handled by IIS.

I did find this interesting code in the ABP source in class Abp.Web.Mvc.Controllers.AbpController in the OnException method:

context.HttpContext.Response.TrySkipIisCustomErrors = true;

but changing this to false did not have any affect.

Thanks

Showing 31 to 34 of 34 entries