2013-07-13 152 views
0

我有一个包含多个.NET网站的网络服务器。我设置它的方式是,服务器的根目录包含每个包含其内容的站点的文件夹。然后,我在根目录中有一个web.config来处理这些URL,并根据他们将要访问的网站将用户指向适当的文件夹。URL重写问题

根目录:

  • \站点A
  • \ SiteB中
  • \ web.config中

这里是web.config文件看起来像这样:

<configuration> 
    <system.webServer> 
     <rewrite> 
      <rules> 
       <clear /> 
       <rule name="SiteA" enabled="true" stopProcessing="true"> 
        <match url="(.*)" /> 
        <conditions logicalGrouping="MatchAll" trackAllCaptures="false"> 
         <add input="{HTTP_HOST}" pattern="^(www\.)?.siteAdomain\.com$" /> 
        </conditions> 
        <action type="Rewrite" url="\SiteA\{R:0}" /> 
       </rule> 
       <rule name="SiteB" enabled="true" stopProcessing="true"> 
        <match url="(.*)" /> 
        <conditions logicalGrouping="MatchAll" trackAllCaptures="false"> 
         <add input="{HTTP_HOST}" pattern="^(www\.)?.siteBdomain\.com$" /> 
        </conditions> 
        <action type="Rewrite" url="\SiteB\{R:0}" /> 
       </rule> 
      </rules> 
     </rewrite> 
     <urlCompression doStaticCompression="true" doDynamicCompression="true" /> 
    </system.webServer> 
</configuration> 

SiteA也使用ASP.NET成员身份:

<authentication mode="Forms"> 
    <forms name=".ASPXFORMSAUTH" loginUrl="~/account/login.aspx" /> 
</authentication> 

问题是,当我去SiteA时,身份验证启动并且我被重定向到loginUrl。然而,它正在解决相对于根文件夹而不是SiteA文件夹的路径,该文件夹导致了404。this site在看过之后提到这是一个用.NET 3.5 SP1修补的错误。但是,我的托管服务位于运行IIS 8.0的.NET 4.X上,所以我认为我应该清楚这一点。

我在这里错过了简单的东西吗?

+0

你试过了吗:LoginURL =“〜/ SiteA/account/login.aspx”或者在SiteA文件夹中放置一个新的Web.Config和Authentication信息。 ? –

回答

0

我可以咨询下面的网站后,来解决这个问题:

http://weblogs.asp.net/owscott/archive/2010/01/26/iis-url-rewrite-hosting-multiple-domains-under-one-site.aspx

基本上,诀窍是要重写只是尚未有站点名称在URL中的子文件夹中的网址:

<rule name="SiteA" stopProcessing="true"> 
    <match url=".*" /> 
    <conditions> 
      <add input="{HTTP_HOST}" pattern="^(www\.)?.siteAdomain\.com$" /> 
     <add input="{PATH_INFO}" pattern="^/SiteA/" negate="true" /> 
    </conditions> 
    <action type="Rewrite" url="\SiteA\{R:0}" /> 
</rule> 
<rule name="SiteB" stopProcessing="true"> 
    <match url=".*" /> 
    <conditions> 
      <add input="{HTTP_HOST}" pattern="^(www\.)?.siteBdomain\.com$" /> 
     <add input="{PATH_INFO}" pattern="^/SiteB/" negate="true" /> 
    </conditions> 
    <action type="Rewrite" url="\SiteB\{R:0}" /> 
</rule>