【问题标题】:Kentico app in sub folder and IIS URLRewrite?子文件夹和 IIS URLRewrite 中的 Kentico 应用程序?
【发布时间】:2013-09-15 23:11:40
【问题描述】:

我在 winhost 上托管一个站点,并且我正在使用 IIS URLRewrite 来允许将主机上的子文件夹映射到子域。

即

~/

~/myapp/

~/KenticoCMS/

在根 web.config 中使用 IIS URL 重写规则将“mydomain.com”的请求路由到 ~/KenticoCMS/,并将“myapp.mydomain.com”的请求路由到 ~/myapp/

目前,当我禁用重写时,mydomain.com/KenticoCMS/ 会正​​常运行。

但是当我启用重写时,我得到一个异常:

[ArgumentOutOfRangeException: startIndex cannot be larger than length of string. Parameter name: startIndex]
System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy) +10698899
CMS.URLRewritingEngine.URLRewriter.CheckPermissions(String siteName, PageInfo pi, Boolean excludeSystem) +235
CMSAppBase.CheckSecurity() +775
CMSAppBase.CMSAcquireRequestState(Object sender, EventArgs e) +606
CMS.CMSHelper.CMSApplicationModule.app_AcquireRequestState(Object sender, EventArgs e) +22
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +136
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69

有人对如何配置网站以使其可以在此设置中工作有任何建议吗?

编辑从根文件夹添加 web.config 并重写代码:

但是,我认为问题在于 Kentico 应用程序认为它位于子文件夹中(确实如此),但没有通过 URL 获取该子文件夹。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <rewrite>
      <rules>
        <rule name="Rewrite to Kentico" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^mydomain.com$" />
          </conditions>
          <action type="Rewrite" url="KenticoCMS/{R:1}" />
        </rule>
        <rule name="Rewrite to Myapp" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^myapp.mydomain.com$" />
          </conditions>
          <action type="Rewrite" url="myapp/{R:1}" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

【问题讨论】:

  • 你能展示你的重写代码吗?
  • @JonoRR 我编辑发布以包含重写规则

标签: iis url-rewriting kentico


【解决方案1】:

所以这是一个很老的问题,但简短的回答是,我认为您的假设是正确的,Kentico 不喜欢 URL 以这种方式被更改。

我之前做过类似的事情,如果其他人遇到这个问题应该会有所帮助,但它执行的是 redirect 而不是 rewrite。

我设置了以下规则:

<rule name="all subdomains" stopProcessing="true">
  <match url=".*" />
  <conditions>
    <add input="{HTTP_HOST}" pattern="(myapp)\.example\.com" />
  </conditions>
  <action type="Redirect" url="http://example.com/{C:1}{URL}" redirectType="Found" />
</rule>

显然,您可以更改重定向类型等,但关键是它是 redirect 而不是 rewrite,所以它并不完全是您所指的在原始问题中。

但是,假设您拥有子域的有效许可证密钥,我不确定您为什么需要或想要通过重写来执行此操作,因为您可以为每个子域设置一个 IIS 站点。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-09
    • 2021-06-24
    • 1970-01-01
    • 2017-07-28
    • 1970-01-01
    • 2017-05-27
    • 2023-03-25
    • 1970-01-01
    相关资源
    最近更新 更多