How to restrict access to a certain file in MVC

好久不见. 提交于 2019-12-08 06:44:30

In order to do this stick the files in a folder under App_Data which will prevent direct access and then you will need to create a controller to handle access to the file. First create a route:

routes.MapRoute("", "Files/{file}", new { controller = "File", action = "View" });

and then apply the Authorize attribute to the action and use

return File(...);

to actually return the file to the user.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!