Redirect ASP pages to a new URL - asp.net

Our old website was built using ASP and now we are using Wordpress (IIS) utilizing a sub-directory. All of the old ASP files are still in the root directory and I'd like to redirect all of these file extensions to our new Wordpress site because the old ASP files are causing 404 errors.
I'm having a real difficult time figuring out what to put in my web.config file so all the old ASP pages are redirected to our new home page.
Thanks

The best option is to use the URL Rewriting extension for IIS ( http://www.iis.net/downloads/microsoft/url-rewrite ) which can also perform regex-based redirections. Create a new rule that matches (.+)\.asp and redirects as appropriate.
I don't know if you just want to do a 'dumb' redirect from all .asp-URIs to your WordPress root, or if you want to intelligently redirect users from the old .asp pages to their new WordPress equivalents (this is a good idea as it means search engine results and previous links won't be broken, I'm sure you can imagine how frustrating it is to follow a link that doesn't go where the user expects).

Thanks everyone for your suggestions, but because I don't have access to the server, my only solution was to work with the web.config file. I simply added the following code and everything now works:
<directoryBrowse enabled="true" />
<httpRedirect enabled="true" exactDestination="true" httpResponseStatus="Found">
<add wildcard="*.asp" destination="/" />
</httpRedirect>

Related

IIS / ASP.NET: One URL returning 403 on one server despite other URLs in site working fine

I have taken over the maintenance of a production website at a new job that is written in ASP.NET 4 Webforms and that runs on IIS 6 on Windows Server 2003. I am not familiar with Webforms nor managing IIS...so I am kind of working things out as I go here.
I have done several deployments to our production server which have worked fine, but am now setting up a test environment that is identical, just a different IP address/domain, so we can properly test changes first.
I have a problem where on this test site any URL that does NOT end with a reference to a file (always .aspx on this site) will return a 403 error on this server. For example http://users.test.oursite.com/admin will always return a 403 error when logged into the site. It should be redirecting to http://users.test.oursite.com/admin/organisation.aspx. Having an MVC background I am not even sure how this happens...but it does in production.
Browsing links within the site is fine as they always reference an .aspx file. Manually typing URLS that reference an .aspx file is fine, just not when the URL does not contain a file. This is not a problem on the production server.
As I said, I am not familiar with WebForms or managing IIS itself...so I have kind of run out of places to look.
Is there anything that comes to mind that I should be looking at that could be causing this problem?
In WebForms typically there is no routing involved.
You need to either provide a full path on the URL ending with .aspx OR
setup default documents for your website. (Index.aspx, Default.aspx etc.)
http://www.iis.net/configreference/system.webserver/defaultdocument
OR
<configuration>
<system.webServer>
<defaultDocument enabled="true">
<files>
<add value="home.html" />
</files>
</defaultDocument>
</system.webServer>
</configuration>
Default documents can be setup in IIS Properties or via web.config.
Otherwise you need to provide the full path.
And because you haven't setup the DirectoryBrowsing (in IIS), you get a 403 Error when you try to access the Directory.
Enable the Directory Browsing option in IIS (not recommended) if you want this error to go away.

urlrewritingnet - rewrite URL with subdomain

I have umbraco website setting on an IIS 7 server: WWW.SITE.COM
I would like rewrite the URL WWW.SITE.COM/SIGUNP to WWW.SIGNUP.SITE.COM
is it possible by using urlrewritingnet or should I configure this by using DNS Host?
I would use HTTP Redirect in IIS to achieve this. I'd recommend using permanent (301) as response status, this will also force most search robots to update their indexes.
Add everything inside the configuration elements to your web.config file
<?xml version="1.0"?>
<configuration>
<location path="signup">
<system.webServer>
<httpRedirect enabled="true" destination="http://www.signup.site.com" exactDestination="false" httpResponseStatus="Permanent" />
</system.webServer>
</location>
</configuration>
exactDestination="false" will turn http://www.site.com/signup/anything/example.html into http://www.signup.site.com/anything/example.html
exactDestination="true" will turn http://www.site.com/signup/anything/example.html into http://www.signup.site.com/
There are several approaches to doing this and Eric's approach is a perfectly valid one. You can also use UrlRewriting.Net as you suggest but I think Eric has suggested the baked in <httpRedirect /> approach as it can be configured in the web.config and therefore also in IIS7 manually.
The disadvantages to this approach however are that:
It needs a developer to update the web.config; or
Someone with access to IIS to change the configuration
It requires an application restart to pick up the redirect rules
There are two other approaches you should consider:
A HttpModule that uses a CSV file containing a cached list of 'from' and 'to' URLs;
A Umbraco-managed doc type that can handle specific path redirects.
The HttpModule approach obviously requires a little coding but is very rewarding. Your SEO team/client can provide a list of URLs that need redirecting and your HttpModule can cache the list (using the file as a dependency) and perform the redirects based upon matched URLs. Any update to the file simply clears the cache automatically.
For basic redirects, I like the approach of having a "Redirect" doc type in Umbraco. This doc type will have two fields, a "redirect type" field (301/302) and a "redirect to" field. In the template for this doc type you will need a little cpde that performs a redirect to the "redirect to" node. Any hits on a page created using this doc type will automatically redirect to the target page. You can also use this doc type in conjunction with "umbracoUrlAlias" field. You can add multiple paths to this field separated by a comma (see this article for an explaination). This way you can catch multiple simliar paths and redirect to a single path.
The advantage of this approach is that it is manageable in the CMS, but the disadvantage is that the redirects are not managed centrally like a CSV file, so you need to be careful in how it is implemented.

Redirect a user when he or she tries to navigate to a page in ASP.NET website

Is it possible to re-direct a request for a page 'XYZ.aspx' to 'ABC.aspx', without writing any code? We are using ASP.Net 4.0 with IIS 7.5.
The idea is that we want to remove XYZ.aspx page from our website, and if users still use old bookmarks that point to XYZ.aspx, then we want them to be taken to ABC.aspx in an automated manner.
there seems to be a few ways, link should hopefully help you out.
http://www.trainsignal.com/blog/iis7-redirect-windows-server-2008
you can forward the user through web.config file or you can do it through IIS too. but I I were you I would use web.config. in shared hosting u cannot touch IIS.
I found the answer. One needs to use the following in web config, and that's it.
<location path="XYZ.aspx">
<system.webServer>
<httpRedirect enabled="true" destination="http://localhost/mysite/ABC.aspx" httpResponseStatus="Permanent" />
</system.webServer>
UPDATE : This will also work if any query string parameters are passed to the page XYZ.aspx.

ASP.NET redirect rule for .cfm file

I have a DotNetNuke application where I am migrating all my old web sites all together under portals.
As users are storing old sites URLs into bookmarks, I need to write redirect rules so they can get properly on new page.
Now, at one point I stuck because I am unable to write rule.
My condition is
URL A
http://www.mydomain.com.cn/auto.cfm?myurl=domain/notice_article.cfm
Should redirect to
http://www.mynewdomain.com/home.aspx
I have implemented this using redirectMaps.
e.g.
<rewriteMap name="MyRedirectMap_Entire">
<add key="whttp://www.mydomain.com.cn/auto.cfm?myurl=domain/notice_article.cfm" value="http://www.mynewdomain.com/home.aspx" />
</rewriteMap>
Adding this properly under web.config file, I able to redirect properly.

Extensionless Page Requests

I have a customer of ours that sent out a publication referring to my site but they used the wrong address...they did not provide a page name...it looks like this:
mywebsite.org/Resources/toolkits/bridging
when it should have been
mywebsite.org/Resources/toolkits/bridging/default.aspx
Is there a way to tell ASP.NET to default to this default.aspx when it sees this kind of request or even better, have IIS 7 handle this easily?
This site is live so I would like to avoid having to introduce code if possible.
As per other suggestions, this should be done in the IIS configuration for your website using the IIS Admin tool.
There is however, another alternative - you can add a section in the web.config of your actual ASP.NET application, allowing you to override the IIS configuration right from your application:
<system.webServer>
<defaultDocument>
<files>
<clear />
<!-- Specify each of your files by order of preference here -->
<add value="Default.aspx" />
<add value="Index.aspx" />
<add value="MyOtherPage.aspx" />
</files>
</defaultDocument>
</system.webServer>
The caveat to this though is it may be a little obtuse when the IIS administrator can't figure out why the server configuration isn't working the way he's got it configured. It's not always right to do something just because you can.
Finally, just in case you don't have access to the IIS server or your IIS administrator has reasons for not adding Default.aspx to the default document list in the IIS configuration and for whatever reason, you don't wish to override the IIS configuration in your web.config file, then the quickest and simplest way is to simply create a file called default.asp in that directory containing:
<% Response.Redirect("default.aspx") %>
Default.asp is in the default document list on IIS. The code will automatically redirect the call to the correct page. The downside to this approach though is that there's a performance hit - every time someone calls default.asp - directly or otherwise, the redirect needs to happen which isn't free.
In the Documents tab of the web site properties in IIS you can specify default documents. If you are using .Net2.0 or later on that machine then Default.aspx should already be set....
Default.aspx is not, oddly enough, set as the default document in an IIS installation; In IIS 7, the setting is under "HTTP Features", called "Default Document". Add default.aspx to that list and you should be OK.
If not, you'll need to add a 404 handler that redirects when it sees that URL.

Resources