MVC2 C# 根据 ID 限制对视图的访问
我有两张表,一张包含职位,一张包含经理,当将职位 ID 传递到“详细信息”视图时,可以访问该职位的详细信息。
Job_id Job_Title Manager_id
23 Chimney Sweep 65
24 Rat Catcher 84
Managers Email
65 [email protected]
66 [email protected]
我想根据 manager_email 限制对视图的访问 - 例如,如果我们在 http://jobsite/ jobs/Detail/23 那么只有 Arthur 可以访问该视图.. 将使用 AD 来挑选用户的电子邮件..
任何指示将不胜感激!
I have two tables one with jobs one with managers, when a job ID is passed to the view 'Detail' the details of that job are accessible.
Job_id Job_Title Manager_id
23 Chimney Sweep 65
24 Rat Catcher 84
Managers Email
65 [email protected]
66 [email protected]
I want to restrict access to the view based on the manager_email - so for example if we're on http://jobsite/jobs/Detail/23 then only arthur can access the view.. will be using AD to pick out the user's email..
Any pointers would be much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以编写一个自定义模型绑定器:
然后拥有您的控制器:
自定义模型绑定器也可以在
Application_Start
中注册:这将简化您的控制器操作:
这种方法的另一个优点是您可以注入依赖项进入自定义模型绑定器的构造函数。当尝试与 AD 和数据库通信时,它可能需要这些依赖项。
You could write a custom model binder:
and then have your controller:
The custom model binder could also be registered in
Application_Start
:which would simplify your controller action:
Another advantage of this approach is that you could inject dependencies into the constructor of your custom model binder. It might require those dependencies when tries to communicate with the AD and the database.