Reputation: 4290
I have an ASP.NET-MVC5 project, the client is a Single Page Application written in AngularJS (only static files needed to launch it, C# Controllers don't serve HTML, they only process AJAX calls). For convenience, all the static files for the Angular part (.html, .js, .css) are in the WebClient
directory located in the root.
Everything works fine with paths like www.my-app.com/webclient/index.html
, but I would like it to work with just www.my-app.com/index.html
. For that I would somehow need to map the WebClient
directory to the root address. What is the best way to do this? Preferably, with just Web.config
file (but any working way is welcome).
P.S. I know that I can write my own controller to do this, but, as far as I understand, it will be slower than built in StaticFileHandler. I'm trying to find a better solution. Thanks in advance.
Upvotes: 1
Views: 1205
Reputation: 4290
Okey, so, as always, the guaranteed way to encounter the answer in the next 5 minutes is to finally ask the question on SO.
The answer is IIS URL Rewrite Module. Found the info on it here
You need to add this to your Web.config (the regexp still needs some work to shield the API route and add all possible symbols)
<system.webServer>
<rewrite>
<rules>
<rule name="Route root to WebClient" stopProcessing="true">
<match url="^([_0-9a-z-./\?]+)" />
<action type="Rewrite" url="WebClient/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
Upvotes: 1