Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi All,

I have static contents(image,videos,etc) inside my folder(say staticcontents).(ASP MVC3)

Is there is any way to make it accessible only from view and not accessible via Url of the content say "www.mydomain/staticcontents/filename".

To serve it from View i am using @Url.Content("AbsolutePathofContent").

In short, I want to expose my static files from a particularfolder only from the View(ASP MVC) and not from Url.


Thanks and Regards
Posted
Updated 7-Oct-15 17:45pm
v2
Comments
Suvabrata Roy 8-Oct-15 0:39am    
Only from view or only authenticated users can view those images / static content?

1 solution

As you are using MVC 3 -> go to global.asax -> go to method RegisterRoutes() and put following code:
C#
routes.IgnoreRoute("staticcontents/{*file}.pdf");
routes.IgnoreRoute("staticcontents/{*file}.dat");
routes.IgnoreRoute("staticcontents/{*file}.gif");

Here it is ignoring files for .pdf, .dat, .gif files. You can change if you have other file format extension.
 
Share this answer
 
v2
Comments
Suvabrata Roy 8-Oct-15 1:13am    
This will allow users to download files without any action filters but I dont think he is asking for the same...

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