Click here to Skip to main content
15,886,545 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
In my project "FilesController" contain "MyFiles" action method with one string argument. And also in the same project there is a folder named "Files" that contain "MyFiles" sub folder. When a user requesting "www.sitename/Files/MyFiles/Pic.jpg" it directly accessing the file from file system instead of hitting the controller action. How to change this request priority form file level to controller level


Controller
C#
public class FilesController : Controller
    {      
        public string MyFiles(string fileName)
        {
            return "abc";            
        }
    }


Note :- We are not using Role authorization
Posted
Updated 21-Sep-14 21:27pm
v2

1 solution

When you running an MVC site you have somewhere a RouteCollection object that responsible to translate your Controller/Action like URLs to actual calls...By default physical path has a precedence over Controller/Action, but you can change that by setting RouteCollection.RouteExistingFiles[^] to true at the point you initialize your routes...
But! As before physical path hide the Controller/Action now Controller/Action will hide physical path! So if that not what you meant to do it's better to rename one of them...
 
Share this answer
 
v2
Comments
Shemeemsha (ഷെമീംഷ) 24-Sep-14 5:05am    
where to set this to true??
in global.asax??
because the RouteCollection.RouteExistingFiles is not coming in the intellisence. Please elaborate the use..thanks
Kornfeld Eliyahu Peter 27-Sep-14 14:46pm    
In a Visual Studio created MVC project you have a piece of code in the App_Strat folder (RouteConfig.cs). That code called from the Application_Start even handler (Global.asax)...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900