[AuthenticateUser]
public class HomeController : Controller
{
//
// GET: /Home/
public ActionResult Index()
{
return View();
}
[AllowAnonymous]
public ActionResult List()
{
return View();
}
}
Cách xóa xác thực cho tác vụ có tên là Danh sách? Vui lòng thông báo ....Có thể vô hiệu hóa bộ lọc xác thực trên một hành động trong bộ điều khiển MVC 5 không?
Mã hóa bộ lọc tùy chỉnh của tôi như sau .. i cũng đã kế thừa cuộc gọi FilterAttribute. Xin cho biết về
public class AuthenticateUserAttribute: FilterAttribute, IAuthenticationFilter
{
public void OnAuthentication(AuthenticationContext context)
{
if (this.IsAnonymousAction(context))
{
}
if (user == "user")
{
// do nothing
}
else
{
context.Result = new HttpUnauthorizedResult(); // mark unauthorized
}
}
public void OnAuthenticationChallenge(AuthenticationChallengeContext context)
{
if (context.Result == null || context.Result is HttpUnauthorizedResult)
{
context.Result = new RedirectToRouteResult("Default",
new System.Web.Routing.RouteValueDictionary{
{"controller", "Home"},
{"action", "List"},
{"returnUrl", context.HttpContext.Request.RawUrl}
});
}
}
}
Các mã dưới đây tạo ra các thông báo lỗi: Lỗi 1 quá tải tốt nhất phương pháp phù hợp cho 'MVC5Features.Filters.AuthenticateUserAttribute.IsAnonymousAction (System.Web.Mvc.AuthorizationContext) có một số đối số không hợp lệ c : \ users \ kirupananthan.g \ documents \ visual studio 2013 \ Projects \ MVC5Features \ MVC5Features \ Filters \ AuthenticateUserAttribute.cs 16 17 MVC5Features Lỗi 2 Đối số 1: không thể chuyển đổi từ 'System.Web.Mvc.Filters.AuthenticationContext' sang ' System.Web.Mvc.AuthorizationContext 'c: \ users \ kirupananthan.g \ documents \ visual studio 2013 \ Projects \ MVC5Features \ MVC5Features \ Filters \ AuthenticateUserAttribute.cs 16 40 MVC5Features
if (this.IsAnonymousAction(context))
Đây có phải là thuộc tính tùy chỉnh của bạn không. Nếu không, có thể '[AllowyAnonymous]' sẽ hoạt động. –
Bộ lọc xác thực được giới thiệu trong MVC 5 .. Không có bộ lọc xác thực được tích hợp .. Đây là Bộ lọc xác thực tùy chỉnh của tôi ... –
nơi được cắm. của 'IsAnonymousAction'? Có gì trong cơ thể nếu có nên có 'return'. –