我正在查看MVC帐户
控制器。…它似乎来自
asp.net?
Scott Guthrie在他的博客文章中很好地解释了这一点
ASP.NET MVC Preview 4
他基本上说MVC示例中的Account Controller使用ASP。NET成员资格提供程序,因此您可以使用其中任何一个。(我认为你可以在互联网上了解更多关于ASP.NET成员资格提供程序的信息。)如果你不想实现/使用其中之一,修改应用程序以使用你自己的用户管理可能是最好的选择。
如何在MVC中使用它
限制登录用户的页面
可以查看吗?你必须全部滚动吗
那是你自己的事吗?
您可以添加
Authorize
属性属于控制器类或动作方法。(相同
source
如上所述)
[Authorize]
public class SomeController : Controller
{
#region Not really important for this example. :]
private IStuffRepository stuffRepository;
public SomeController(IStuffRepository stuffRepository)
{
if (null == stuffRepository)
{
throw new ArgumentNullException("stuffRepository");
}
this.stuffRepository = stuffRepository;
}
#endregion
public ActionResult Index()
{
return View();
}
[Authorize(Roles="Moderator")]
public ActionResult Flag(int id)
{
this.stuffRepository.Flag(id);
return RedirectToAction("Index");
}
[Authorize(Roles="Admin,SysOp")]
public ActionResult Delete(int id)
{
this.stuffRepository.Delete(id);
return RedirectToAction("Index");
}
[Authorize(Users="COMPANY\\joed")]
public ActionResult ChangeId(int oldId, int newId)
{
this.stuffRepository.ChangeId(oldId, newId);
return RedirectToAction("Index");
}
}