我在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>
所以这是一个相当古老的问题,但简短的回答是我认为你的假设是正确的,Kentico 不喜欢以这种方式更改 URL。
我之前做过类似的事情,如果其他人遇到此问题,这应该会有所帮助,但它会重定向而不是重写。
我设置了以下规则:
<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>
显然,您可以更改重定向类型等,但关键是它是重定向而不是重写,因此它并不完全是您在原始问题中指向的内容。
但是,假设您拥有/拥有子域的有效许可证密钥,我不确定您为什么需要或想要通过重写来执行此操作,因为您可以为每个子域设置一个 IIS 站点。