如何将所有 IIS 请求路由到我的 MVC 应用程序?
我正在创建一个 MVC 3 应用程序来管理客户公司的业务。部署时,传入请求应突出显示客户公司的名称;因此, http://hosteddomain.com/Excelsior/Home/Dashboard/3
应从客户端 Excelsior 检索用户的主页。
问题 1:在开发服务器上,这工作正常 (localhost:28497/ClientCompany/...
),因为我的 RouteConstraint
查找企业名称。但是,当我部署它时,如何告诉 IIS 将所有请求发送到我的应用程序?现在,IIS 将查找名为“ClientCompany”的应用程序。
问题2:有更好的方法吗?例如,使用 ClientCompany.hosteddomain.com/SomeAppName/[pages...]
形式的 URL。如果是这样,我如何告诉 IIS 将请求重新映射到我的应用程序,以及如何从 MVC 应用程序内部获取客户公司的名称?
元问题 1:也许更好的问题 1 是如何使我的应用程序成为 IIS 的默认网站?
感谢您的见解 埃里克
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在问题#2 中,您可以从
HttpContext.Current.Request
访问原始URL。你可以从那里找到任何你想要的东西。我会在 IIS 中为单个应用程序设置主机标头,然后解析 url 并从那里执行您需要的任何操作。
编辑
唯一需要注册的域名是 TLD(顶级域名),因此
subdomain.tld.com 只是一个子域,您需要为其创建 DNS 条目,然后设置IIS 主机标头。
看看这个:http://technet.microsoft。 com/en-us/library/cc753195(WS.10).aspx
请注意,如果我没记错的话,如果您使用 SSL,主机标头将不起作用。
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.
您需要在
global.asax注册路由代码>.您只需定义要接受的模式并指定控制器和操作参数。
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.