How to remove the redirect from an ASP.NET 5 webapi and return HTTP 401? -


following answer on this question, have added authorization on default, using following code:

public void configureservices(iservicecollection aservices) {   aservices.addmvc(options =>   {      var lbuilder = new authorizationpolicybuilder().requireauthenticateduser();       var lfilter = new authorizefilter(lbuilder.build());      options.filters.add(lfilter);    });     aservices.addmvc(); }  public void configure(iapplicationbuilder aapp, ihostingenvironment aenv, iloggerfactory aloggerfactory) {   aapp.usecookieauthentication(options =>   {     options.authenticationscheme = "cookies";     options.automaticauthentication = true;   }); } 

however when tries access unauthorized, returns (what seems default) redirect url (http://foo.bar/account/login?returnurl=%2fapi%2ffoobar%2f).

i want return http 401 only, instead of redirect.

how can in asp.net 5 webapi?

by url redirected assume you're using cookie authentication.

you should desired results setting loginpath property of cookieauthenticationoptions null or empty described 1 of users.

app.usecookieauthentication(options =>         {             options.loginpath = "";         }); 

it working it's not working anymore (because of this change).

i've submitted bug on github this.

i'll update answer once gets fixed.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -