我在 IIS 服务器虚拟目录上托管多个应用程序,我正在使用 URL 重写来促进它们。像这样手动编写的所有图像和其他 Assets "~/path/to/my/content"
有正确的输出 "/path/to/my/content"
,但捆绑路径如 "~/client/js"
给出输出 "/myapplication/client/js"
应该是 "/client/js"
.
我该如何解决?
我如何启动脚本包:
var scriptBundle = new ScriptBundle("~/client/js");
重写配置:
<rule name="Official Website" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" matchType="Pattern" pattern="^(www\.)?domain\.com$" ignoreCase="true" negate="false" />
</conditions>
<action type="Rewrite" url="officialsite/{R:1}" />
</rule>
正在研究这些主题,但无法为我做任何事情:
更新:我使用 Winhost 作为主机提供商,他们不支持为 IP 设置主机头,可能是由于共享 IP。它们提供指向根文件夹的域指针,这就是我使用 URL 重写的原因。
最佳答案
你说 :
I'm hosting multiple applications on IIS server virtual directories and I'm using URL Rewrite to facilitate them
所以,问题是指根配置(虚拟目录)可用于捆绑等,而不是捆绑配置或重写规则。我认为您需要将 myapplication 目录设置为虚拟目录并将其设置为单独的网站。确保您已遵循 Create Web Site 中提供的说明它说:
you add a Web site in IIS, a site entry is created in the ApplicationHost.config file. The entry specifies:
- network binding for the site
- Maps the site to a location in the file system
- optionally specifies user credentials for content access
为确保用户请求到达正确的网站,您必须为服务器上的每个站点配置唯一标识。可以使用以下唯一标识符区分托管在同一服务器上的网站。
Configure a Host Header for a Web Site (IIS 7)指向第一个。
更新 : 我认为服务器和您的项目可能存在名称冲突。更亮的尝试换客户端
~/client/js
和它的文件夹到新的。除非有多个路径选择(具有此路径深度)供服务器获取,否则您可以通过添加 \
添加额外的深度来解决它。在您的项目和 js 包映射中。更新 2 : 最后,我建议您关注 How to publish or host subdomain on winhost.com? 中提供的完整文章解决这个惊人的问题:)
关于asp.net-mvc - MVC 包和 IIS 虚拟目录(URL 重写),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31282221/