IIS 7 URL Rewrite config issue or MVC Route?

有些话、适合烂在心里 提交于 2019-12-11 06:48:55

问题


I have an account with Gearhost.com and when it comes to setting up sub-domains you are currently required to go in and configure an URL Rewrite entry using IIS Remote Admin.

The directory folder structure follows the pattern:

\mastersite
\mastersite\subdomain1

The Gearhost KB Article on how to do it can be found here: https://support.gearhost.com/KB/a851/setting-a-subdomains-content-location-using-url-rewrite.aspx?KBSearchID=0

This works just fine, but I ran into a scenario that revealed the ability to access the sub-domain by using the master.com/sub-domain path.

subdomain1.site.com (works)
www.site.com/subdomain1 (displays site also --which I don't want)

I don't know if the KB article is the correct way to configure sub-domains in IIS or if I need to manage the routing in my Microsoft MVC 3 Application.

Let's say it is the correct way to setup/configure a sub-domain. Is there a way to restrict the path for the 2nd option, so it returns as page not found or access forbidden or something to this effect?

I'm developing a Microsoft MVC Application and if I use a "Request.Url" call, it actually returns the full path of the 2nd option even when I'm sitting on what looks like a perfect path to the sub-domain home page.

So I don't know if this needs to be handled a different way, if the URL Rewrite entry needs to be changed, or what the solution may be.

Looking for feedback from any engineers who may have more knowledge on the topics.

Thanks.


回答1:


I ran across an article which solved my original request for help.

It involved creating Outgoing rules in IIS, to rename the path. The rule looks for the path in question and then rewrites it.

Per the article I used Outgoing rule # 2.

Pre-Condition: None
Matching Scope: Server Variable
Variable Name: RESPONSE_LOCATION
Variable Value: Matches the Pattern
Using: Regular Expressions
Pattern: ^(?:MyMasterSiteSubFolder/MySubDomain|(.*//[_a-zA-Z0-9-\.]*)?/MyMasterSiteSubFolder/MySubDomain)(.*)
[x] Ignore case
Action: Rewrite
Action Properties Value: {R:1}{R:2}
[x] Replace existing server variable value
[ ] Stop processing of subsequent rules


来源:https://stackoverflow.com/questions/12854705/iis-7-url-rewrite-config-issue-or-mvc-route

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