asp.net-mvc - MVC 包和 IIS 虚拟目录(URL 重写)

标签 asp.net-mvc url-rewriting iis-7 bundling-and-minification virtual-directory

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

正在研究这些主题,但无法为我做任何事情:
  • How do I get System.Web.Optimization bundles to work with custom folders in an IIS virtual directory?
  • CssRewriteUrlTransform with or without virtual directory
  • Why does ResolveBundleUrl not work for custom folders? (MVC Beta 4)
  • Is it possible to unit test BundleConfig in MVC4?

  • 更新:我使用 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:

    1. network binding for the site
    2. Maps the site to a location in the file system
    3. optionally specifies user credentials for content access


    为确保用户请求到达正确的网站,您必须为服务器上的每个站点配置唯一标识。可以使用以下唯一标识符区分托管在同一服务器上的网站。
  • 主机头名称(推荐)
  • IP地址
  • TCP 端口号

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

    相关文章:

    c# - DropDownList - 以编辑形式显示的选定值

    regex - 如果在任何地方使用 .htaccess 找到,重定向并删除 slug

    c# - 在 MVC 之外使用 Razor 模板引擎(具有完整的 mvc razor 支持)

    c# - ASP.NET MVC 表单验证。您如何在非模型对象上执行此操作?

    IIS URL 重写 ASP

    wcf - 如何续订 iis7 自签名 ssl 证书

    iis-7 - GetObjectContext 在 VB6 COM dll 中不返回任何内容,从经典 ASP 调用

    asp.net-mvc - 仅向授权用户提供 ASP.NET 中的静态文件

    javascript - 与客户端一起路由 GET 请求

    .htaccess - htaccess seo 友好的 URL