subdomain rewriting in ASP.NET?

*爱你&永不变心* 提交于 2019-12-09 01:21:16

问题


How do i do this in .NET? http://why.does.my.head.asplode.net/ I want to do something like ytmnd where each url is a different user generated page. I might need something as simple as pointing to a directory so dirname.mysite.com will redirect to http_public/userGenContent/dirname/


回答1:


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.




回答2:


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 ;).




回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/1322151/subdomain-rewriting-in-asp-net

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