Tag: 授权

CustomAuthorizationPolicy.Evaluate()方法永远不会在wcf webhttpbinding中触发

我可以看到我创建了一个wcf服务: [OperationContract] [PrincipalPermission(SecurityAction.Demand, Role = “Admin”)] [WebInvoke(Method = “GET”, UriTemplate = “/Data/{data}”)] string GetData(string data); 所以我创建了一个自定义授权,你可以看到: public class AuthorizationPolicy : IAuthorizationPolicy { string id = Guid.NewGuid().ToString(); public string Id { get { return this.id; } } public System.IdentityModel.Claims.ClaimSet Issuer { get { return System.IdentityModel.Claims.ClaimSet.System; } } // this method gets called after the authentication stage […]

FormsAuthentication.SetAuthCookie在MVC 5中没有

我创建了一个全新的ASP.NET MVC 5项目,用FormsAuthentication.SetAuthCookie测试[Authorize]属性。 我只是在一个动作中设置一个cookie(在我的Home控制器中): public ActionResult About() { FormsAuthentication.SetAuthCookie(“someUser”, false); 我限制访问另一个: [Authorize] public ActionResult Contact() { 当我启动我的网页并导航到/home/contact ,我被正确地重定向到登录页面。 然后我转到/home/about ,获取我的cookie,然后返回联系页面。 但是我仍然被重定向到登录页面 – cookie没有validation/授权我。 在调试器中,当我多次加载About页面时, HttpContext.User.Identity.IsAuthenticated == false (也就是说,即使在设置了auth cookie之后,它也从未将我视为已经过身份validation)。 这里必须要做一些额外的步骤吗? 我不应该为基本身份validation设置自己的IPrincipal,我应该吗?

如何获得使用System.Diagnostics.Process.GetProcess(string)的权限?

我正在使用Microsoft Visual Studio制作一个简单的远程任务管理器以用于体验目的。 我想使用Process.GetProcesses(string); 但有一个访问被拒绝的exception,不允许我进入远程计算机进程。 事实上它是正常的,因为我们应该使用用户名和密码进行身份validation, 但是如何 ?

ASP MVC C#:是否可以将动态值传递给属性?

好吧,我是C#的新手,我正在尝试使用ASP MVC2创建一个小网站。 我想创建自己的授权属性。 但如果可能,我需要传递一些值。 例如: [CustomAuthorize(GroupID = Method Parameter?] public ActionResult DoSomething(int GroupID) { return View(“”); } 我想授权访问页面。 但它取决于传递给控制器​​的值。 因此授权取决于groupID。 这有可能以任何方式实现这一目标吗? 提前致谢。

ASP.NET 5针对两个或多个策略进行授权

是否可以针对两个或更多策略应用授权? 我使用的是ASP.NET 5,rc1。 [Authorize(Policy = “Limited,Full”)] public class FooBarController : Controller { // This code doesn’t work } 如果没有,我如何在不使用政策的情况下实现这一目标 有两组用户可以访问此控制器:“完整”和“有限”。 用户可以属于“完整”或“有限”,或两者都属于。 它们只需要属于两个组中的一个以访问该控制器。

自定义授权属性在WebAPI中不起作用

public class CustomAuthorizeAttribute : AuthorizationFilterAttribute { protected override bool AuthorizeCore(HttpContextBase httpContext) { return true;// if my current user is authorised } } 上面是我的CustomAuthorizeAttribute类和 [CustomAuthorize] // both [CustomAuthorize] and [CustomAuthorizeAttribute ] I tried public class ProfileController : ApiController { //My Code.. } 当我打电话的时候 http://localhost:1142/api/Profile 它没有触发CustomAuthorizeAttribute 我的FilterConfig类的内容如下所示 public class FilterConfig { public static void RegisterGlobalFilters(GlobalFilterCollection filters) { […]

有人可以向我解释这个ASP.NET MVC代码块吗?

这是ASP.NET MVC2(RTM) System.Web.Mvc.AuthorizeAttribute类中的当前代码: – public virtual void OnAuthorization(AuthorizationContext filterContext) { if (filterContext == null) { throw new ArgumentNullException(“filterContext”); } if (this.AuthorizeCore(filterContext.HttpContext)) { HttpCachePolicyBase cache = filterContext.HttpContext.Response.Cache; cache.SetProxyMaxAge(new TimeSpan(0L)); cache.AddValidationCallback( new HttpCacheValidateHandler(this.CacheValidateHandler), null); } else { filterContext.Result = new HttpUnauthorizedResult(); } } 因此,如果我’授权’然后做一些缓存的东西,否则抛出401 Unauthorized响应。 问题: 这3条缓存线有什么作用? 欢呼:)

ASP.NET IAuthorizationFilter OnAuthorization

嗨,我正在尝试实现自定义授权filter //The Authourization attribute on a controller public class CustomAdminAuthorizationFilter : IAuthorizationFilter { private readonly IAuthentication _authentication; public SageAdminAuthorizationFilter(IAuthentication authentication) { _authentication = authentication; } public void OnAuthorization(AuthorizationContext filterContext) { bool result = _authentication.Authorize(filterContext.HttpContext); } } 正如你在OnAuthorization上看到的那样,我得到的结果是假的。 我需要设置什么才能返回我来自哪里? 编辑: 它似乎仍然让我直接进入登录页面 我注射了IAuthetication this.BindFilter(FilterScope.Controller, 0); Bind().To(); 然后我在控制器中装饰我的动作。 [Authorize] public ActionResult Index() { ViewBag.Title = “Welcome”; ViewBag.Message = […]

使用自定义消息的MVC 3 AuthorizeAttribute重定向

如何创建自定义AuthorizeAttribute,以字符串参数的forms指定消息,然后将其传递到登录页面? 例如,理想情况下这样做会很酷: [Authorize(Message = “Access to the blah blah function requires login. Please login or create an account”)] public ActionResult SomeAction() { return View(); } 然后,在Login操作中,我可以这样做: public ActionResult Login(string message = “”) { ViewData.Message = message; return View(); } 最后在视图中我可以这样做: @if (!String.IsNullOrEmpty(ViewData.Message)) { @ViewData.Message } blah blah 基本上我想将自定义消息传递到登录页面,以便我可以显示特定于用户在该特定时间尝试访问的消息。

授权角色WebAPI oauth owin

我在ASP.NET Web API上使用OWIN中间件实现了令牌授权系统。 我成功地可以使用REST客户端进行身份validation并获取授权令牌来调用API。 如果我将[Authorize]属性放在我的控制器中的GET操作上,它也可以正常工作。 如果我没有有效的令牌,它会拒绝带有401消息的资源,但是如果我将[Authorize(Roles=”admins”)]与roles参数一起使用,则它无法识别用户的角色。 我validation了数据库中的内容,并检查了用户usersinroles是否正确填充。 这是一段代码: [Authorize(Roles = “admins”)] public IEnumerable Get() { ClaimsPrincipal principal = Request.GetRequestContext().Principal as ClaimsPrincipal; bool isrole = principal.IsInRole(“admins”); 我还检查了没有roles参数的动作,并且isrole boolean总是为false 。 我必须启用某些function吗?