开发者

asp.net global.asax Application_BeginRequest

I have a site with multiple domains pointing to it. I wanted to redirect all requests to main domain so I've created a method called RedirectToRealDomain("domain.com") to check and redirect all requests to my preferred domain

At the moment it lives on Session_Start but I am planing to move it to Application_BeginRequest event.

Is that good idea? As I understand Session_Start only raised when new session started but Application_BeginRequest raised on all requests. RedirectToRealDomain method doesn开发者_StackOverflow中文版't do any DB lookups or anything expensive apart from comparing strings.


Yes, that will work. I use an HTTP module's "BeginRequest" event to do the same thing on my site.

Another option is to create a 2nd IIS site and point all of the other domains to this site. Then you can use the IIS management console to redirect all requests to the 1st site.


This should be fine, but there are other non-programming ways of doing this from within IIS, which I presume would be less overhead and probably a more "correct" way of doing it. Your understanding of when the events are raised is correct, though and your solution should work and not be too much of a server drain.

See here for how to do it in IIS:

http://www.getfoundnow.com/iis_301_redirect.htm

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜