开发者

How do i create a custom 404 page and send a 404 msg?

I know how to redirect pages with Rewrite. But whe开发者_StackOverflow中文版n there is a 404 page how would i display my own custom 404 page (i know i can rewrite it) and say this is in fact a 404 and not just a plain rewritten page?

-edit-

How i can SET the error code instead of asking the server? if the user goes to /user/invaliduser/ i would like to send a 403 or 404 but my rewrite would send it to a valid page to display user info so i would like to know how to say doesnt exist rather then empty fields in a page.


To be more flexible then strict 404.html follow my example. In Global.asax.cs override:

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);
}

For example my 404.aspx contains form to send feedback, 403.aspx - exposes more interesting items for user, and 500 sends alert to Admin.


U can do a 404.html and redirect the 404 error in the web.config file to your own file

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜