views:

101

answers:

1

I have a site that is hosted in shared hosting environment. They use a wildcard subdomain setup and suggest using Response.Redirect to achieve the illusion of a subdomain.

Is there a way of doing this such that the "switch" takes place on the server rather than bouncing back down to the browser first?

Server.Transfer only works if I transfer to an actual resource. So redirecting from sub1.mydomain.com to www.mydomain.com/public/ does not work. I'd have to redirect to www.mydomain.com/public/mypage.aspx instead which i dont want to do.

A: 

To ensure that the "switch" takes place on the server, you could create a simple HTTP Module to intercept each request, inspect the requested URL and then forward them as needed . All your module has to do is handle the OnBeginRequest event, and then forward the request. In this way you could really have unlimited sub-domains.

Also might want add a blank host header, so that any requests for subdomains not listed get forwarded to the proper default website

If you aren't familiar with them, modules are very simple to create and work with. Heres a link to a very similar implementation by Brendan Tompkins: http://codebetter.com/blogs/brendan.tompkins/archive/2006/06/27/146875.aspx

You could also do some URL rewriting in the module should you need specific URL "look" behavior.

PortageMonkey
You're describing a form of URL rewriting, but the resulting URLs won't be visible to end users. For example, domain.com/subdomain/page.aspx can be caught and rerouted on the server, but the change wouldn't be visible to users. Also, if the domain and subdomain are running on the same web site, the final page may be the same.
RickNZ
Based on the question posed, I did not discern this to be a requirement.
PortageMonkey