【发布时间】:2016-06-15 19:02:51
【问题描述】:
当用户登录时我写了这段代码:
FormsAuthentication.SetAuthCookie(form.username, true);
return RedirectToAction("Index", "Users",new { id = myUser.userid });
现在在 UserController 中,我有这个操作可以检索 url 中特定 id 的所有数据
[Authorize(Roles = "user")]
public ActionResult Index(int id)
{
return View(x.psostTBLs.Where(n => n.post_userid == id).ToList());
}
现在每个登录用户都可以访问所有其他用户页面
示例:如果我以用户 100 身份登录,我可以访问网站中的所有其他页面并编辑其数据
localhost:3343/user/100
localhost:3343/user/200
localhost:3343/user/300
在视图中我需要这样的东西:
if(i'm logged in as user 100 and i'm in page localhost:3343/user/100)
{
edit
delete
.... etc
}
else if(i'm logged in as user 100 and i'm in page localhost:3343/user/200 or any other page)
{
only I can read the content
}
【问题讨论】:
标签: c# asp.net-mvc model-view-controller roles