Question

We've got a test site hosted only by IP address. We really need to test some functionality that depends on what subdomain someone is using to get to the site. But of course we can't even USE subdomains with an IP only site.

So, one thought I had was that instead of subdomains, we could have the testers open the site with a URL like this: http://192.168.0.1/smith or http://192.168.0.1/jones and I would then redirect them to http://192.168.0.1/default.aspx?site=smith etc...

Our testers are at the client, and asking them to enter in the querystring would be problematic. Plus, I'd really like to get a quick intro into URL Rewriting.

Can anyone give me any idea if what I want to do is possible, and if so, a pointer to some code or explanation or something?

We are using asp.net 3.5 and iis6, I believe.

Thanks for any help!

Was it helpful?

Solution

I wrote up an introduction to URL Rewriting in ASP.NET on my blog, for what its worth. Feel free to post more questions here to clarify any specific issues you have.

OTHER TIPS

this will definitly work in your situation http://www.urlrewriting.net/149/en/home.html

we have implemented same what you required is, its open source dll and you need to write some rules in web.config, according to your scanario, your rule something like

<add name="index" virtualUrl="^~/(.*)/Default.aspx" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="~/Default.aspx?site=$1&amp;urw=t" ignoreCase="true"/>

you could possibly change the hosts file on the testing machine to point domains (and subdomains) at that IP, that way you wouldnt have to rely on DNS and could test as if the domains were assigned.

more information here:

http://labnol.blogspot.com/2004/10/tweak-your-windows-hosts-file.html

this is part of .Net 3.5 and is the same mechanism used by MVC

This makes your life easy, due to the fact that everything is held in the HttpContext.CurrentContext.Items[""]

I have adapted this code for a few project where I have an XML configuration file. I then use this file to build the RouteCollection. This code has also been easily extended to handle 301 redirects for SEO.

This method is also loaded once in your AppPool and removes the need to parse xml files and configurations for every call. This so far has been the best solution for me performance wise.

If you need any assistance please let me know. I will gladly lend a hand.

Edit : 13/09/09

I have not run into that problem yet since I usually handle the membership / authentication verification in every page. I usually have a control or method I call on the page to validate/ authorize a user. My clients rarely use the ASP.Net membership, they usually rely on proprietary sub systems which we need to connect to.

I have extended the examples provided in the above links so that I can write one xml routing table which gets loaded when the application starts up or when I force a RouteCollection update.

so far this has proven itself to work pretty well. this can also allow for a change in routes while the application is running, with no down time.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top