c# - Authorize(Roles="Admin") does not work -


i'm writing asp.net application identity authorization engine. wrote custom user , role stores , seem work correctly. however, unknown reason, attempt use authorize role on controller's action fails , redirects home/index. action looks following:

[authorize(roles = "admin")] public actionresult manage() {     return view(); } 

the redirection being done silently, cannot hook debugger anywhere (especially action filtering being done before running action).

i guess may not enough diagnose problem, tell me in comments, additional information need , i'll edit question.

why doesn't work?


edit: configuration in startup.cs

    public void configuration(iappbuilder app)     {         dataprotectionprovider = app.getdataprotectionprovider();          app.createperowincontext<applicationusermanager>(() => dependencyresolver.current.getservice<applicationusermanager>());          app.usecookieauthentication(new cookieauthenticationoptions         {             authenticationtype = "applicationcookie",             loginpath = new pathstring("/account/login")         });                 } 

edit: action:

    [allowanonymous]     public async task<actionresult> index()     {         // returns false         if (user.isinrole("admin"))             system.diagnostics.debug.writeline("ok");          var usermanager = unityconfig.container.resolve<applicationusermanager>();         // returns true         if (await usermanager.isinroleasync(user.identity.getuserid<int>(), "admin"))             system.diagnostics.debug.writeline("ok");          return view();     } 

a couple of things check:

  1. what login page set to? i'm guessing either unauthenticated or unauthorized, , mvc sending login page (which set or defaulted "/"
  2. if sure logged in (authenticated), double check user indeed have admin role (is authorized).
  3. i believe user store has method can override see what's returned user's roles. it's worth setting breakpoint there , see what's going on.

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -