How to serve static files via MVC after login (I am trying to add angular mini SPA to my large MVC project)

Look for suggestions on hosting static files through an MVC app.

I have a MVC SPA (basically a bunch of static html, js and img files). I want users to only be able to access these static files after they have logged into my MVC application. I am running Windows Server Platform using IIS.

I am currently doing this:

RouteTable.Routes.IgnoreRoute("AngularApp/{*path}"); //to serve up angular files from AngularApp folder


However, this has a number of problems.

I don't want to ignore the route, I want the MVC controller to check if the user has permissions (like my other controllers), if not redirected to the login page, and if so, instead of sending them to the view, let them load any files to a specific folder or subfolders. But the folders from which these files are loaded must be different than the requested route url. For example, I don't want users to come to, but if they request, I want it to serve the file from there.

It seems to be just a question about the ability to redirect MVC and fetch files from another folder, but I have no idea how.

Can anyone know about MVC please give me a step by step easy way to do this? When I try to extract files outside of the views folder, this seemingly simple task results in different permissions and other kinds of errors because I don't know how to do it correctly.


PS To clarify, I know how to get my controller to check permissions and redirect to any file in the views folder, but how do I do this for the entire files and directories folder in the higher level folder? I want to map out a route, go to the controller, and instead of going to the view, I want it to move me into static files. I suspect there is a way to use maproute () in global.asax to help me do this, but I don't have much experience with that.


source to share

1 answer

I can simplify, but I usually select Application in IIS Manager and then select Mime Types, they add mappings for whatever types you want to display statically. I've done this for HTML and JSON files before and it worked fine. Use type = text / javascript or application / json etc.



All Articles