Hello Everyone today I’m gonna teach you, if the user type a URL that doesn’t
even exist, so how to rediect them to a Existing Page without showing them the
default 404 Error Page.
We will use the web.config file for this purpose, this can also be done in
IIS via URLReWrite
1. First Add 2 webpage and name them home.aspx and Error.aspx
2. Now open your web.config
3. Find <System.Web> tag
4. Now place the following code inside the <System.Web> tag
1. First Add 2 webpage and name them home.aspx and Error.aspx
2. Now open your web.config
3. Find <System.Web> tag
4. Now place the following code inside the <System.Web> tag
<customErrors
mode="On">
<error
statusCode="404" redirect="Error.aspx"/>
</customErrors>
This code will check the url , if the url exist than this code will do nothing, but if the page doesn’t exist it will rediect them to Error.aspx page.
Note
This code will check the url , if the url exist than this code will do nothing, but if the page doesn’t exist it will rediect them to Error.aspx page.
Note
- Error Code 404 means Page Not Found
- You can Change the StatusCode according to your requirements
- If CustomErrors mode is set to Off than this rule will not do anything
- 1xx Informational
- 2xx Success
- 3xx Redirection
- 4xx Client Error
- 5xx Server Error
No comments:
Post a Comment