subdomain rewriting in ASP.NET?

拈花ヽ惹草 提交于 2019-12-01 00:44:36

HAHA ...

I handled the Begin request event in global.aspx for this because my urls come from sql server.

Why are so many people sub domain crazy these days?

in Begin Request you can do something like this (not usre exactly because I aint got it in front of me right now) ...

request.rewriteurl( "new url" );

... this will take whatever the source url is and "redirect" without a redirect the response to a url you can use internally.

I suggest you use UrlRewritingNet. You may have to add a rule similar to this:

      <add virtualUrl="http://(.*).asplode.net/index.aspx"             
       rewriteUrlParameter="ExcludeFromClientQueryString"  
       destinationUrl="~/Users.aspx?username=$1" 
       ignoreCase="true" /> 

I cannot test this since I'm on a Linux machine right now, but it should work ;).

The various UrlRewriting tools will help you once you have the request getting into ASP.NET, however before that happens you need to setup IIS to pass these requests to your app. This is simple enough if there's only one app on the server, but more difficult otherwise.

Check out http://msmvps.com/blogs/bernard/archive/2005/03/22/39218.aspx for some details on wildcard subdomains on IIS.

Alternatively use an IIS level rewriter like ISAPI Rewrite

Essentially search for IIS wildcard subdomain to find a wealth of approaches.

Well, IIS7 has built url rewrite functionality. You can specify rules etc in web.config. But for IIS6 you need ISAPI dll that does the same for you. I've used IIRF and it works just fine.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!