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.

A single page app is static html, css and javascript files a folder with an index.html file and a number of folders for css, images and javascript.

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.

When I do this by loading and serving the index.html file, then I cannot figure out how to serve all the css and javascript files used by the index.html file because they are referenced by the index.html with relative paths like "css/style.css" and "js/somejavascript.js".

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?

Answers


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:

js/script.js
css/style.css

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.


Need Your Help

Calling a Haskell function from Ruby on Heroku

ruby haskell heroku

So I'd like to call a Haskell function from a Ruby app running on Heroku. I'm aware of Hubris, but it seems unlikely to work in the Heroku sandbox, so I'm thinking of automatically converting the

How to replace PHP imagecopyresampled with Amazon S3?

php jquery amazon-s3 jquery-file-upload

I'm using the jquery file upload script and have had success uploading the main image to Amazon S3. I'm now trying to swap out the multiple image sizes for uploads to sub folders or objects in S3.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.