ASP.Net Redirection with Specific Extension - asp.net

I need to redirect 404 pages that have an extension of CFM (ColdFusion). The old site was run under ColdFusion and now is a pure ASP.Net 4.0 site. The site is not MVC. I would like to take the parameters that are passed and direct to the new page.
Anyone know how I can achieve this?

Just let ASP.NET redirect the request to a custom 404 page and check for the file extension there.
Read out the file extension, check for CFM and do a 301 (Moved permanently) redirection via codebehind.

I'm not an expert, but could you just take the whole address and do the string manipulation to check whether the website address contains ColdFusion extension and after it pass the parameters as a QueryString to the suitable address?
String manipulation would be helpful especially if parameters from the ColdFusion URL match the ones needed for .NET URL.

Related

Httphandler for ASP Classic?

Is there any way in ASP Classic to catch HTTP request before it comes to that page? Like in ASP.Net we can catch request at Application_BeginRequest.
Actually what I'm trying to do is to redirect requests to some other pages if asking files from a certain directory. My application is hosted on IIS6. And I suppose IIS6 by default doesn't support for url rewrite. Directory browsing is already disabled.
It would be nice if it could be done just putting a web.config in that certain directory to redirect to other pages.
e.g.
Original Requests:
Https://stackoverflow.com/NoReadWriteFolder/file1.asp
Https://stackoverflow.com/NoReadWriteFolder/file2.html etc
and I'd like to redirect to
Https://stackoverflow.com/ReadOnlyFolder/someOtherFile1.asp
Https://stackoverflow.com/ReadOnlyFolder/someOtherFile2.html
I googled but so far no luck, any clue would highly be appreciated.
background:
My application runs for different companies (countries in actual fact) that use the same application.
I use include file called default.asp that runs as standard include for all the scripts I serve. I catch domain requests in URL, detect which company this and then redirect to a URL that I build that includes company code and a "URL prefix" which is added to the URL throughout the session.
To do this, I read URL using request.servervariables, set Session variables, work out my URL prefix and based on this, create revised URL which I then response.redirect.
I hope this may give you an idea for your situation.
For IIS6 I have used Ionic's Isapi Rewrite Filter
https://iirf.codeplex.com/
It supports URL re-writes and re-direction and should do exactly what you need.
On the examples and help pages there are examples for you to re-direct.

shortening url to cms

Hi
We have a CMS application that lets people create websites under our domain.
The system was built a few years ago and it used a method that transfers parameters such as website id, folder code and more using the url. this method created a giant url for every item in the website
For example:
My domain is www.domain.com
A users website on my domain is www.domain.com/user
and every time that a user enters his website he gets a link like this
www.domain.com/page.aspx?code=blablasdsdsdsdsds&folder=blablablablablabla and more.
We are trying to reduce the string size in the url.
What are our options? can we show the user one url like a virtual one and still work the same with the old url?
We are trying to locate a solution that wont make us rewrite our entire application.
the application is built in c# and the web server is iis 6.
Thanks
You are searching for URL rewriting.
For IIS7 this functionality is build-in via the URL Rewrite Module.
For IIS6 you should read this MSDN article to follow the details on how to do it:
URL Rewriting in ASP.NET
Or you could go with one of the numerous third-party tools to do it:
UrlRewritingNet.UrlRewrite
UrlRewriter.NET
Ionics Isapi Rewrite Filter
ISAPI_Rewrite

URL Redirects in ASP.NET

Ok, wierd problem I cant figure out. Hopefully someone where can. I have inherited a site that was developed with a very over-architected Content Management System. I am having problems now with the redirection functionality built into it.
This is on a dedicated Windows 2003 server running ASP.NET 3.5 sp 1. The redirects are stored in the database, and I have confirmed that the correct redirect is in place in the database. Finally, the file extension .html has been mapped in IIS to the ASP.NET ISAPI. And there is an HttpHandler created to redirect the .html requests. The default documents on the server, in order, are:
default.aspx
index.aspx
default.asp
index.asp
default.html
index.html
for this example, we have two redirects both pointing to the same content page. /example and /example.html
when requesting /example.html it correctly finds the appropriate redirect in the database and does its magic. Bueno. When requesting /example it gives a 404 page. Its not even the asp.net yellowish 404 generic error page. Its the standard vanilla IIS 404 response so it appears that asp.net is not intercepting these requests.
Let me know if any other information is requested and I will try to provide what I can. Thanks in advance for all the great recommendation I am sure will come from the community.
You should be able to map a wildcard extension to go through the ASP.Net ISAPI DLL is the solution.
Installing Wildcard Application Mappings (IIS 6.0) may also be useful.
Without rewriting the CMS, you can put a physical file in a new directory "/example". This will trigger ASP.NET to intercept the request, and hopefully load your page.
If you want to really hack it up you can change the IIS 404 page to be a .NET page in your application that can handle the original request and redirect to the page you really want.
Yes this is correct because /example is not pointing to any file, it is pointing to directory in the web server. Check that Default.aspx/ default.html or any other atleast one of them exists in your app.
If you are using ASP.Net MVC for REST then check your actions are properly written.

How to do 301 redirects in asp.net from old Apache mod_rewrite style urls when moving a site from php to asp.net?

I have an existing site in php running on Apache using the mod_rewrite plug-in. In other words, I currently have urls like www.example.com/section/subsection/ which Google and others have indexed.
However, the site needs a major upgrade, and I would like to move it to asp.net. I only have the option of using a shared hosting solution (iis 6, aps.net 3.5, full trust). So my question: How do I make asp.net do a 301 redirect from my old urls like www.example.com/section/subsection/ to their equivalent ones on the new asp.net site?
I obviously needs this to not loose the current rankings in the search engines.
Thanks, Egil.
If you use the ASP.NET MVC framework it has a URL rewriting system built into it.
You can manually add 301 redirects into IIS using IIS Manager if you want to set up "moved" locations.
If you want to do URL re-writing then you will need to implement IHttpModule, hook up the BeginRequest event, and add that new class to the httpModules section in Web.config.
Okay...so this may be overkill and could possibly be done another way in two lines..BUT...
If you are keeping the same domain name then what I've done in the past is keep a table of old urls and how they map to new urls. On the application's request, I'll scan the table, if an old url is found then I'll add a header that does a 301 redirect to the new URL.
According to Steve Sanderson’s blog post Deploying ASP.NET MVC to IIS 6 it do not look like there is an option to do url rewriting/redirection with IIS6 in a shared hosting set up, where you cant manually configure IIS. Gah...

Why doesn't url rewrite work?

In asp.net 3.5, I'm rewriting the url
http://www.abc.com/archive/1108/harpersdecember
to the following
http://www.abc.com/article.aspx?docId=78
I'm using this code to do it:
Context.RewritePath("/article.aspx?docId=78");
It works fine locally but when I upload to the remote web server, I get a 404 when trying to reference the above page. Any suggestions why it works locally but not remotely?
You may need to create a wildcard mapping in IIS on the remote server so that all requests are processed by ASP.Net. If you do not do this any URLs without .ASPX on the end will not run through your URL rewriting code.
There is a good explanation of this (and other reasons you might use it) on Scott Guthrie's blog.
Not "may" - you definitely need to create a wildcard mapping. Visual Studio uses the cassini web server which essentially passes all requests through .net. IIS only forwards specific mapped requests (by default .aspx, .asmx, etc..) to .net - rewriting a URL in asp.net requires adding a new mapping to get the request to asp.net in the first place
Sounds to me like the production server does not have a default aspx page, ie: default.aspx. If it did, it would reroute the request to your handler.
Easy way to verify this, would be to create a directory and place a default.aspx file in it and try to request it using only the dir name, ie: server.com/newdir/
If that gives you a 404, then you know it for sure.

Resources