开发者

Dynamic user permission to secure folders in MVC3

Using MVC3 I am trying to come up with method of checking the database to see if a user is allowed access to a folder. The administrator has individual control over each user's permission to courses, so I cannot control this from web.config.

The screenshot below provides an example of what I am trying to accomplish: courseA is an example of one of many folders that only certain users will be allowed access to. My thinking is that I could use a CourseController action like OpenCourse(int id) to check against the db if a user has access to a course, and if so then "allow access" to the entire course folder and open the player.html file contained within it. The user's permission to each file within courseA folder would probably need to persist for the user's session.

Dynamic user permission to secure folders in MVC3

Is it even possible to do something like this from wi开发者_JAVA百科thin the MVC View folder, or should the courseA folder sit somewhere else?


You can enforce this sort of restriction in your database calls. You could say for example:

var courses =  ListCoursesForUser(userId);

Then when accessing a specific course you can reuse this:

public doSomethingWithCourse(courseId, userId)
{
   var courses =  ListCoursesForUser(userId);

   if(courses.Any(c => c.courseId == courseId))
   {

   }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜