Serve static single page apps (static html) to only authenticated users with ASP.NET MVC
I am making an ASP.NET MVC site which needs to serve a number of single page apps.
I have no problem serving the single page apps from a virtual directory in an IIS server, but I would like to serve them only to authenticated users in the ASP.NET MVC solution, and therefore I am right now trying serve the index.html files from a controller method.
I am using the relative parts to make it easy to develop and debug the single page apps independently from the ASP.NET MVC solution.
So my question is basically, how can I serve static HTML files with relative urls to css and js files to only authenticated users in an ASP.NET MVC site?
If I'm understanding: you have some static HTML files that you can't/don't want to change, with relative URL link. In that case, just construct your MVC route so that the relative paths work. For example, let's say the relative paths are like this:
When you send that back to the browser, it's going to resolve those paths relative to the current path. So if you're serving the HTML file from the route (say):
Then the browser will send requests to:
So adjust the route accordingly, and make sure any alternate routes redirect to the main one, eg /home/index should redirect to /home.