Search code examples
asp.netiisiis-10

How to make IIS respect relative path?


In IIS 10 I have running a website on port 4553. Locally this website runs fine. Because I want to expose this website to the endusers, I need to:

  1. Make it available through Azure Application gateway.
  2. Route port 4553 to 443 using a deeplink in the URL, because the proxy of the end-user only allows traffic through port 443. I can't make port 443 default for the IIS solution, because port 443 is already occupied for another web solution.

I got this all working:

The landing page for example contains:

@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
<script src="~/Scripts/jquery.dataTables.min.js"></script>

AAG/IIS doesn't understand this path. Although the landing page do work, IIS tries to find the jquery scripts for example in "https://external.website.com/Scripts/jquery.dataTables.min.js" while it should be "https://external.website.com/iis/solution/Scripts/jquery.dataTables.min.js" So the script doesn't respect that adding of iis/solution in the URL.

When I manually change it to

<script src="~/iis/solution/Scripts/jquery.dataTables.min.js">
</script>"

it does work.

But it's too much to change this for all HTML and other source files. Plus it can't make these changes each time the IIS solution does need an update.

My question; is there something on a higher level which I can change in the IIS settings or in the landing page, which makes sure the file is taken from the right path? Or is it an option to change the physical path for example?


Solution

  • Are you hosting the application under a virtual directory instead of an application "solution"? If so, IIS won't be able to load the correct URL.

    Please ensure you are hosting the project in a virtual application instead of either a folder or virtual directory.

    https://learn.microsoft.com/en-us/iis/configuration/system.applicationhost/sites/site/application/

    If you don't want to do that, you can rewrite the html <script> tag with outbound rule. In rendered html page, it should looks like

    and you can rewrite it to

    https://learn.microsoft.com/en-us/iis/extensions/url-rewrite-module/creating-outbound-rules-for-url-rewrite-module