Base solution for your next web application

Activities of "devkev2403"

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

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.

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;

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.

UPDATE: there is a problem with using httpErrors which is that it stops the error messages from UserFriendlyException being displayed. I am going to read up more on this but wanted to update this thread.

No problem. I haven't really made any more progress :(

system.web/CustomErrors must be on for text in UserFriendlyExceptions to be displayed on the client.

Status code 401-Unauthorized should not have an explicit customError as this causes issues with redirection to the login page.

system.webServer/httpErrors can not be on or it also breaks UserFriendlyException. I haven't got to the bottom of why but assume it is in ABP framework code.

To add more detail to this, this is a problem!

customErrors must be on for UserFriendlyException. This is fine.

httpErrors must be off for UserFriendlyException.

But then, if the user attempts to visit a URL they don't have permission for, IIS displays its default 403 error page because you can't have httpErrors configured in web.config.

Issue created -- customErrors and httpErrors Conflict #533

Question

Hi,

how exactly should the "Remember Me" checkbox on the login page work?

Currently I use a cookie so ticking or unticking the checkbox makes no difference. If the user does not explicitly logout, the next time they open their browser they are automatically logged in. This is not what I want.

Thanks

Answer

Hi Aaron, that was exactly the information I was looking for! Thank you.

Showing 1 to 10 of 34 entries