authorize-attribute

How to authorize a set of controllers without placing the annotation on each one?

梦想的初衷 提交于 2019-11-30 03:52:56
问题 I have sets of controllers which are each used for each authorization type. For example, a class A authorization will have a set of controllers each which require class A authorization. Is there a way to place one [Authorize(Role="Class A")] attribute somewhere which will apply to each of those controllers without having to decorate each controller with the same attribute? 回答1: You can initialize those controllers derived from your base controller. namely put your attribute on a controller

ASP.NET Login Redirect Loop when user not in role

只谈情不闲聊 提交于 2019-11-30 03:28:13
问题 I'm in a bit of a bind with implementing Roles in ASP.NET MVC 5. I am attempting to log in as a user that does not have a role required to access the area of the application I'm trying to reach. What I would expect in this scenario is, I'm redirected to the login page again, and will be until I enter a set of credentials that do have access or I navigate to another area of the application. What is actually happening is that the application appears to go into a login redirect loop, debugging

A controller action which returns a partial view inserts the logon page when authorization fails

半城伤御伤魂 提交于 2019-11-29 20:29:05
I have a view that loads a partial view from a controller action using jQuery. The controller action is decorated with the Authorize attribute and if the user has timed out when that action is called intead of being redirected to the proper LogOn page, the LogOn page gets inserted in the view where the partial view would have gone. There is another post here that describes a solution using jQuery but unfortunately it doesn't include any code samples which is what I need because I'm not very familiar with jQuery (and new to web development) and I need to get this issue resolved as soon as I can

Can someone explain this block of ASP.NET MVC code to me, please?

走远了吗. 提交于 2019-11-29 14:55:44
问题 this is the current code in ASP.NET MVC2 (RTM) System.Web.Mvc.AuthorizeAttribute class :- 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),

How to find Controllers with [Authorize] attributes using Reflection in C# (or How to build Dynamic Site.Master Menus)

大城市里の小女人 提交于 2019-11-29 13:49:53
问题 Maybe I should back-up and widen the scope before diving into the title question... I'm currently writing a web app in ASP.NET MVC 1.0 (although I do have MVC 2.0 installed on my PC, so I'm not exactly restricted to 1.0) -- I've started with the standard MVC project which has your basic "Welcome to ASP.NET MVC" and shows both the [Home] tab and [About] tab in the upper-right corner. Pretty standard, right? I've added 4 new Controller classes, let's call them "Astronomer", "Biologist",

Is it possible to override the default behavior of [Authorize] in ASP.NET MVC?

拈花ヽ惹草 提交于 2019-11-29 02:08:07
I wondered if/how I can override the default [Authorize] behavior in ASP.NET MVC. I know that I can create a new Action Filter, make my own attribute and so forth; I am merely interested if I can simply change the [Authorize] behavior and replace its workings with my own code? Edit : Guys and Girls. I appreciate your input but as I wrote, I am not looking to introduce a new [XYZAuthorize] Attribute. I'm aware of how to do this. I want to keep the [Authorize] notation but just change how it works. Yes, take a look at the MSDN docs for AuthorizeAttribute: http://msdn.microsoft.com/en-us/library

ASP.Net Core 2.0 mixed authentication of JWT and Windows Authentication doesn't accept credentials

点点圈 提交于 2019-11-28 18:55:27
I've API created in asp.net core 2.0 where I am using mixed mode authentication. For some controllers JWT and for some using windows authentication. I've no problem with the controllers which authorize with JWT. But for the controllers where I want to use windows authentication I am indefinitely prompted with user name and password dialog of chrome. Here my sample controller code where I want to use Windows Authentication instead of JWT. [Route("api/[controller]")] [Authorize(AuthenticationSchemes = "Windows")] public class TestController : Controller { [HttpPost("processUpload")] public async

A controller action which returns a partial view inserts the logon page when authorization fails

陌路散爱 提交于 2019-11-28 16:31:44
问题 I have a view that loads a partial view from a controller action using jQuery. The controller action is decorated with the Authorize attribute and if the user has timed out when that action is called intead of being redirected to the proper LogOn page, the LogOn page gets inserted in the view where the partial view would have gone. There is another post here that describes a solution using jQuery but unfortunately it doesn't include any code samples which is what I need because I'm not very

Dynamically add roles to authorize attribute for controller

丶灬走出姿态 提交于 2019-11-28 03:24:24
I need to enable my admin user to change access permissions for users on the fly, such that they can create new Roles and add permissions to those Roles. I want to be able to create an Authorize attribute to stick above my controller class that I can add roles to from a database, so that I don't have to 'set' the roles during development, as in [Authorize(Roles="Role1, Role2")] etc. So something like [Authorize(Roles = GetListOfRoles()] I found this question - ASP.NET MVC Authorize user with many roles which does something similar but maybe there's a way to change this such that it gets a list

is there an authorizeattribute equivalent to just standard web forms (not MVC) for .net

放肆的年华 提交于 2019-11-27 16:07:43
I'm working on a project that will use windows role providers and I want to limit functionality to certain AD groups. With MVC, I could use an AuthorizeAttribute above my action methods and redirect accordingly. Is there something similar I can do for a standard web forms application (.NET 3.5) that doesn't use MVC? You can set this up in web.config with the authorization element. <configuration> <system.web> <authorization> <allow roles="domainname\Managers" /> <deny users="*" /> </authorization> </system.web> </configuration> Basically domain groups are translated into roles when using