2016-09-07 19 views
0

ASP.NET MVC 5で記述されたWebアプリケーションがあります。このアプリケーションにはユーザーに関する情報が含まれています。今度は、自分のウェブサイトのサブドメインとしてアクセス可能な各ユーザーのプロフィールページを作成したいと考えています(例:user1.example.comuser2.example.com、...)。ASP.NET URL MVC 5のサブドメインルーティングのIIS URL書き換えルール

これらのサブドメインにはHTTP経由でアクセスできますが、残りのアプリケーションではHTTPSを使用する必要があります。

IIS上でWebアプリケーションを実行するので、URL書き換えルールを使用してuser1.example.comからexample.com/Profile/Index?name=user1に書き換えた場合には最適であると判断したので、Webアプリケーション自体は使用されているサブドメインについて知る必要はありません。私はこれらの書き換えルールを思い付いた:

<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.comexample.com/Profile/Index?name=user1と力HTTPSにuser1.example.comを書き換えません。

誰かが私に理由とその理由を説明してくれますか?

答えて

0

私はこのコードを使用して終了:

<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> 

何私は混乱していたが、それは私が特定のテナントを持っている必要がありますページのみなのでインデックステンプレート内のURLヘルパーは、System.Web.HttpException: Cannot use a leading .. to exit above the top directory.を投げ始めた私が与えたという事実でしたリンクをハードコードし、すべてが正常に動作するようになりました。