Redirecting from 404 pages to a new page using ASP.Net

Sorry if this was asked ... could not find any good answers. There are several ASP tutorials that show this code:

<% Response.Redirect "http://www.w3schools.com" %> 

but where do I put this code if the source file does not exist? and do you need to insert code in the source file to tell the server to switch from the OLD file to the NEW file if people try to access the old file?

I know how to do a redirect for a server that can accept redirects using PHP in a .htaccess file. But this site I'm working on will not accept the code that I have, which usually works.

On page 404 you will see:

Server error in "/ pagehere" application. Resource could not be found. Description: HTTP 404. The resource you are looking for (or its dependencies) may have been deleted, its name changed or temporarily unavailable. Review the following URL and make sure it is spelled correctly.

Requested URL: / pagehere

Version Information: Microsoft.NET Framework Version: 4.0.30319; ASP.NET Version: 4.0.30319.34280

I want to do a redirect from oldpage.php to newpage.php. oldpage.php no longer exists.

Which file can I create or modify and what code can I use for redirection? Thanks!

+5
source share
1 answer

If you can control your web.config, you can add persistent redirects.

A good quick link is at https://www.stokia.com/support/misc/web-config-response-redirect.aspx

From this site you can do individual redirects.

 <configuration> <location path="bing.htm"> <system.webServer> <httpRedirect enabled="true" destination="http://bing.com" httpResponseStatus="Permanent" /> </system.webServer> </location> <location path="google.htm"> <system.webServer> <httpRedirect enabled="true" destination="http://google.com" httpResponseStatus="Permanent" /> </system.webServer> </location> <location path="yahoo.htm"> <system.webServer> <httpRedirect enabled="true" destination="http://yahoo.com" httpResponseStatus="Permanent" /> </system.webServer> </location> </configuration> 

Here you can put oldpage.html in the location tag.

 <location path="oldpage.html"> 

Then you place the newpage.html uder httpRedirect tag.

 <httpRedirect enabled="true" destination="newpage.html" httpResponseStatus="Permanent" /> 

Compatible with this.

 <location path="oldpage.html"> <system.webServer> <httpRedirect enabled="true" destination="newpage.html" httpResponseStatus="Permanent" /> </system.webServer> </location> 
+1
source

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


All Articles