【发布时间】:2012-07-19 14:08:16
【问题描述】:
我已经编辑了我的问题,这是我用于实现身份验证的代码。
继承 AuthorizeAttribute 的类。
public class FBxAuth : AuthorizeAttribute
{
public FBxAuth()
: base()
{
}
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
bool isAuthenticated = false;
if (httpContext.User.Identity.IsAuthenticated)
{
// here I will check users exists in database.
// if yes , isAuthenticated=true;
}
return isAuthenticated;
}
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
{
filterContext.HttpContext.Response.Redirect("/home/Register/?returningURL=" +
filterContext.HttpContext.Server.UrlEncode(filterContext.HttpContext.Request.Url.ToString()));
}
}
我的控制器
[FBxAuth]
public ActionResult Index()
{
teamDA = new TeamDataAccess();
var teams = teamDA.TeamsList();
return View(teams);
}
- 我的方法是否正确?
2.如何检查经过身份验证的用户是否有权在控制器中执行操作。
例如:删除。
www.abc.com/teams/5/delete 将执行删除
我可以从 UI 中隐藏删除链接。
但是,如果用户尝试通过提供上述 url 来删除,我该如何阻止他执行该操作?
【问题讨论】:
标签: c# asp.net-mvc authentication authorization security