How to create a custom 404 page and send 404 msg?

I know how to redirect pages using Rewrite. But when there is a 404 page, how can I display my own 404 page (I know I can rewrite it) and say that it is actually 404, and not just a rewritten page?

-edit -

How can I set an error code instead of a server request? if the user goes to / user / invaliduser / i, I would like to send 403 or 404, but my rewriter would send it to a valid page to display information about the user, so I would like to know how to say it doesn’t exist, not empty fields in p.

+3
source share
2 answers

, 404.html . Global.asax.cs :

public void Application_Error(Object sender, EventArgs e)
{
        if (HttpContext.Current.Request.IsLocal) return;

        Exception ex = Server.GetLastError();
        HttpException httpEx = ex as HttpException;
        string errorUrl;
        if (httpEx != null && httpEx.GetHttpCode() == 403)
            errorUrl = "~/error/403.aspx";
        else if (httpEx != null && httpEx.GetHttpCode() == 404)
            errorUrl = "~/error/404.aspx";
        else
            errorUrl = "~/error/500.aspx";
        Server.Transfer(errorUrl);
}

, 404.aspx , 403.aspx - , 500 .

+2

U 404.html 404 web.config

<error statusCode="404" redirect="YOURFILE.htm" />
+1

Source: https://habr.com/ru/post/1729371/


All Articles