8

I'm hosting multiple applications on IIS server virtual directories and I'm using URL Rewrite to facilitate them. All images and other assets that are manually written like this "~/path/to/my/content" has a correct output "/path/to/my/content", but bundle paths like "~/client/js" gives an output "/myapplication/client/js" which should be "/client/js".

How can I fix that?

How I initiate Script bundle:

var scriptBundle = new ScriptBundle("~/client/js");

Rewrite configuration:

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

Was looking into these topics, but couldn't make anything work for me:

UPDATE: I'm using Winhost as hosting provider, and they do not support setting up host headers for the IP, probably due to the shared IP. They provide domain pointers to root folders, which is why I'm using URL rewrite.

Community
  • 1
  • 1
skmasq
  • 4,470
  • 6
  • 42
  • 77
  • You've told us you're rewriting, but you've decided to not show your rewrite rules too? It looks like they might be part of the problem. – spender Jul 08 '15 at 01:50
  • It seems to me that you want to use multiple websites linked to port 80 and differentiated by the host name. You don't need to use URL rewrite for that. Can [this](http://forums.iis.net/t/1197454.aspx) be what you are after? – milanio Jul 14 '15 at 12:36
  • @milanio Hi, I'm using winhost as my hosting provider, and the only thing I can do is set domain pointers to appropriate root folder. They do not offer setting up host headers like in the link you provided. Thank you thou. – skmasq Jul 14 '15 at 12:41

2 Answers2

0

You said :

I'm hosting multiple applications on IIS server virtual directories and I'm using URL Rewrite to facilitate them

So, The problem refers to root configuration (Virtual Directory) to be usable for bundling and etc.., It's not about bundling configuration or rewrite rule. I think you need to setup myapplication directory as virtual and set it up as a separate website. Make sure you have followed instructions available in Create Web Site where it says:

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

To ensure that user requests reach the correct Web site, you must configure a unique identity for each site on the server.Web sites hosted on the same server can be distinguished using the following unique identifiers.

  • Host header name (recommended)
  • IP address
  • TCP port number

Configure a Host Header for a Web Site (IIS 7) points to the first one.

Update: I think there may be a name conflict on server and your project. more brightly try to change client in ~/client/js and its folder to new one. Unless there were multiple path choices (with this path depth) for server to fetch that you can solve it by adding an extra depth by adding an \ in your project and js bundle mapping.

Update2: Finally I suggest you to follow full article available in How to publish or host subdomain on winhost.com? to solve such this amazing issue :)

Amirhossein Mehrvarzi
  • 18,024
  • 7
  • 45
  • 70
  • Thank you for answer. I followed these instructions (http://goo.gl/MGceH5) on how to create those virtual directories and I was able to set up two different sites with different subdomains and everything on both sites work except the bundling aspect (even html relative paths `~/Content` resolve to `/Content` not `/myapplication/Content`, which is what I need). For example if I take out `/myapplication` from '/myapplications/client/js?v=123123` it fetches me the correct bundled js file. `ApplicationHost` configuration file, I have no access to it, and I cannot set-up IIS bindings. – skmasq Jul 16 '15 at 13:40
  • Folder structure I have is `Content/client/js`, but the resolved bundle path is `client/js` which has never conflicted. Just to point out, bundling doesn't work only in this virtual directory scenario. – skmasq Jul 16 '15 at 13:52
  • @skmasq any way it refers to using `myapplication` instead of `content` by default. – Amirhossein Mehrvarzi Jul 16 '15 at 14:01
  • @skmasq my last help will be the second update in my post. good luck my friend. – Amirhossein Mehrvarzi Jul 16 '15 at 14:09
0

I have two options you can try.

1) Try using this to trick it into using the correct path:

var scriptBundle = new ScriptBundle("~/../client/js");

You may get an HttpException (Cannot use a leading .. to exit above the top directory.), but it's worth a shot. I cannot replicate your environment, so I cannot test.

2) Create your own virtual path provider: Changing ASP.net application root?

Community
  • 1
  • 1
Daniel
  • 502
  • 2
  • 9
  • 18
  • I tried your first suggestion, unfortunately it just ended up as an error. Regarding the second suggestion, I am not really grasping the concept of`VirtualPathprovider` and with the provided sample I have troubles to retrieve file. – skmasq Jul 20 '15 at 03:16