사용자에 대한 정보가 들어있는 ASP.NET MVC 5로 작성된 웹 응용 프로그램이 있습니다. 이제는 내 웹 사이트의 하위 도메인 (예 : user1.example.com
, user2.example.com
등)에 액세스 할 수있는 각 사용자의 프로필 페이지를 만들고 싶습니다.ASP.NET URL의 하위 도메인 라우팅에 대한 IIS URL 다시 쓰기 규칙
HTTP를 통해 이러한 하위 도메인에 액세스 할 수있게하고 나머지 응용 프로그램에서는 HTTPS를 사용해야합니다.
나는 그래서 내가 example.com/Profile/Index?name=user1
에 user1.example.com
를 재 작성 URL 재 작성 규칙을 사용하는 경우가 가장 좋은 것입니다 생각 IIS의 웹 응용 프로그램을 실행하므로 웹 응용 프로그램 자체가 하위 도메인을 사용하는 것에 대해 알 필요가 없습니다 것입니다. 나는이 재 작성 규칙 내놓았다 :
<rewrite>
<rules>
<clear />
<rule name="Rewrite user subdomains into query string" stopProcessing="true">
<match url="^(.+)" />
<conditions>
<add input="{HTTP_HOST}" negate="true" pattern="^www\.example\.com$" />
<add input="{HTTP_HOST}" pattern="^([^.]+)\.example\.com$" />
</conditions>
<action type="Rewrite" url="/Profile/Index?name={C:1}" />
</rule>
<rule name="Redirect to https without www" stopProcessing="true">
<match url="(.*)" />
<conditions trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^www\.example\.com$" />
<add input="{HTTP_HOST}" pattern="^example\.com$" />
</conditions>
<action type="Redirect" url="https://example.com/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
이 코드는 불행하게도 심지어 user1.example.com
이상 example.com/Profile/Index?name=user1
과 힘 HTTPS에 user1.example.com
를 다시 작성하지 않습니다.
누군가 제발 설명해 주시겠습니까? 그리고 어떻게 고칠 수 있습니까?
는 사실은, 인덱스 템플릿에 해당 URL 헬퍼가 나는 특정 세입자가 필요 유일한 페이지입니다 때문에System.Web.HttpException: Cannot use a leading .. to exit above the top directory.
가 발생하기 시작했다 나 한테 무슨 혼란했다, 내가 준
<rewrite>
<rules>
<clear />
<rule name="Rewrite url with tenant subdomain" stopProcessing="true">
<match url="^$" /> <!-- So resources like user1.example.com/Content/css wouldn't be affested by this rewrite -->
<conditions>
<add input="{HTTP_HOST}" negate="true" pattern="^www\.example\.com$" />
<add input="{HTTP_HOST}" pattern="^([^.]+)\.example\.com$" />
</conditions>
<action type="Rewrite" url="Profile/Index?subdomain={C:1}" />
</rule>
<rule name="Redirect to www.example.com" stopProcessing="true">
<match url="(.*)"/>
<conditions>
<add input="{HTTP_HOST}" pattern="^example\.com$"/>
</conditions>
<action type="Redirect" url="https://www.example.com/{R:1}" redirectType="Permanent" />
</rule>
<rule name="Redirect to https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://www.example.com/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
: