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

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -