Reputation:
I'm new to development with .NET and working on a personal project. My project will allow users to create their own simple mobile site.
I would like to write a HTTP Module that will handle pseudo sub-domains.
I have already setup my DNS wildcard, so sub.domain.com
and xxx.domain.com
etc. point to the same application. I want to be able to extract sub and ID parts from sub.domain.com/pageID.html
URL and load settings of the page from a database server in order to build and render the page to the client.
I can do it with URL rewrite tools like isapirewrite
, but I want my application to be independent from OS so that the server doesn't require installation of any 3rd party app.
Is it possible to do it with HTTP handlers?
Can anyone post an example?
Upvotes: 1
Views: 1864
Reputation: 9258
You can check the domain at any time. Where to do it dependings on your application's goals. E.g. if you want to serve different pages depending on the domain you could do like this:
public class MyModule : IHttpModule
{
public void Dispose()
{
}
public void Init(HttpApplication context)
{
context.BeginRequest += context_BeginRequest;
}
void context_BeginRequest(object sender, EventArgs e)
{
HttpApplication app = sender as HttpApplication;
string host = app.Request.Url.Host;
if(host == "first.domain.com")
{
app.Context.RewritePath("~/First.aspx");
}
}
}
Upvotes: 5