2
当我写了这个代码的用户的loggedIn:在UserController中ASP.net MVC获得用户的角色从网址检索特定ID
FormsAuthentication.SetAuthCookie(form.username, true);
return RedirectToAction("Index", "Users",new { id = myUser.userid });
现在我有这样的行动,检索特定ID的所有数据网址
[Authorize(Roles = "user")]
public ActionResult Index(int id)
{
return View(x.psostTBLs.Where(n => n.post_userid == id).ToList());
}
现在每天登录的用户可以访问所有其他用户的网页
例子:如果我登录的用户100我可以访问所有其他页面的网站和编辑数据
本地主机:3343 /用户/ 100
本地主机:3343 /用户/ 200
本地主机:3343 /用户/ 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
}
感谢名单及其工作 –
如果你喜欢,最多投票请! :d –