How to route all IIS requests to my MVC app?

家住魔仙堡 提交于 2020-01-06 02:33:18

问题


I'm creating an MVC 3 app that manages business for client companies. When deployed, incoming requests should prominently feature the name of the client company; thus, http://hosteddomain.com/Excelsior/Home/Dashboard/3 should retrieve the home page for a user from client Excelsior.

Question 1: On the development server this works fine (localhost:28497/ClientCompany/...) because my RouteConstraint looks up the business name. However, when I deploy this, how do I tell IIS to send all requests to my app? As it is now, IIS will look for an app named "ClientCompany".

Question 2: Is there a better way to do this? For example, using URLs of the form ClientCompany.hosteddomain.com/SomeAppName/[pages...]. If so, how do I tell IIS to remap the requests to my app AND how do I get the name of the client company from inside the MVC app?

Meta-Question 1: Maybe a better question 1 is how do I make my app be the Default Web Site for IIS?

Thanks for insight Eric


回答1:


On Question #2, you can get access to the raw url from the HttpContext.Current.Request. You can find out anything you want from there.

I would setup Host Headers in IIS for a single application, then parse the url and do whatever you need to from there.

EDIT

The only domain name that needs to be registered is the TLD (Top Level Domain), so

subdomain.tld.com is just a sub domain that you need to make a DNS entry for and then setup the IIS Host Headers.

Have a look at this: http://technet.microsoft.com/en-us/library/cc753195(WS.10).aspx

Note that Host Headers don't work if you are using SSL if I remember correctly.




回答2:


You need to Register Routes in your global.asax. You just define the pattern you want to accept and designate the controller and action parameters.



来源:https://stackoverflow.com/questions/8096937/how-to-route-all-iis-requests-to-my-mvc-app

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