开发者

ASP.NET 3.5 webforms URL Routing question

I'm attempting to configure URL routing in my ASP.NET 3.5 WebForms app. Setting up routes has always been confusing to me, so I was hoping I could get some direction.

My requirement is fairly simple. I'm setting up different "brands" of my application, and I'd like the brand to be specified in the URL. For example, http://www.mysite.com/brand1/Default.aspx would bring up one brand (code behind would look up brand1 in the db and load specific text, images, themes, etc) and http://www.mysite.com/brand2/Default.aspx would bring up another brand, etc.

I'm fairly flexible wit开发者_JS百科h how the URLs are displayed, with the exception of keeping the http://www.mysite.com/brand1 prefix. That cannot be changed.

Thanks for any help!


I do this by using http://www.UrlRewriter.net, as explained here by Scott Gu:

http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx

The trick is to use URL rewriting rules (Regular Expressions) in your web.conifg to get a request for /brand1/default.aspx to actually execute /Processor/Default.aspx?brand=brand1, for example.

NB: The Form.browser trick worked a treat for me when doing postbacks.


Another possible answer from me...

If you're using IIS 7 there is a handy built in module for URL Rewiring, all controlled through a GUI if that's your preference:

http://learn.iis.net/page.aspx/460/using-the-url-rewrite-module/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜