Why is my IgnoreRoute not working?

I want to deny users access to my folder "~ / Content / ...", which I wrote as described in "Global.asax.cs", and put this line of code at the beginning of every other routes.IgnoreRoute("Content/{*pathInfo}");
But that does not work. in fact, the user can see all the files in the content folder by the type of URL in the browser. Did I miss something?

+4
source share
2 answers

How did you find out that this does not work? Give an example.

You may have placed the latter in the routing table. So try moving it so that it is added to the first routing table. The route collection is an ordered list of routes.

Also try the following: Routes.IgnoreRoute("Content/"); but your ignore version is also correct and should work.

Finally, I don’t know what you mean when you say that the user can see the entire contents of the Content folder: Isn't that right? The user should be able to download files from the folder, and we usually just need MVC to ignore requests coming into the structure, and therefore IIS can directly serve these files.

or did you mean that browsing is enabled and you want to disable it: in this case, go to IIS Manager and select your site and find the option to view the directory and disable it, as shown here .

+4
source

Your problem cannot be resolved with routing restrictions. There are 3 important steps in a processing request:

  • IIS received the request.
  • IIS look in the file system and look for a direct match to the file
  • If IIS did not find any file, it provides an ASP.NET MVC request for processing.

So, you need to configure the folder protection to forbidden direct access to files, but allow access to the application, as here . But I do not recommend protecting the folder that should be used. I do not believe that your site should not have images. :) If you have protected content, you need to create another folder.

+2
source

All Articles