web api - Web api 302 status redirect -


i have project angularjs , webapi2 , formauthentication. because need import old code webforms project uses session store user variables, have implement session in webapi.

in webconfig have:

`

 <authentication mode="forms">       <forms loginurl="/index.html" defaulturl="/areas/modeler/modeler.html" name=".aspxformsauth" protection="all" cookieless="usedeviceprofile" slidingexpiration="true" path="/" domain="" requiressl="false" timeout="600" enablecrossappredirects="false">       </forms> </authentication> <authorization>         <allow users="*" /> </authorization> <machinekey validationkey="xxxxx" decryptionkey="xxxxxx" validation="sha1" /> </system.web> <location path="scripts">     <system.web>         <authorization>             <allow users="*" />         </authorization>     </system.web> </location> <location path="~/authenticate">     <system.web>         <authorization>             <allow users="*" />         </authorization>     </system.web> </location> 

`

i made following changes in global.asax.cs implement session:

`

public override void init()         {             this.postauthenticaterequest += application_postauthorizerequest;             base.init();         } protected void application_start()         {             arearegistration.registerallareas();             globalconfiguration.configure(webapiconfig.register);             globalconfiguration.configuration.includeerrordetailpolicy = includeerrordetailpolicy.always;         } protected void application_postauthorizerequest(object sender, eventargs e)         {             var url = httpcontext.current.request.apprelativecurrentexecutionfilepath;             var auth = context.request.isauthenticated;             httpcontext.current.setsessionstatebehavior(sessionstatebehavior.required);         }` 

after user inputs name , password, call post method ~/authenticate/login.

in chrome browser network tab can see next 2 line: login method: post, status 302 login method get, status 405 first call:

remote address:[::1]:52966 request url:http://localhost:52966/authenticate/login request method:post status code:302 found response headers view source content-length:166 date:thu, 14 may 2015 13:11:24 gmt location:/(s(tdd41h23pms5lllzyro1hltq))/authenticate/login server:microsoft-iis/8.0 x-powered-by:asp.net x-sourcefiles:=?utf-8?b?rdpcuhjvamvjdh..............=?= request headers view source accept:application/json, text/plain, */* accept-encoding:gzip, deflate accept-language:en-us,en;q=0.8,ro;q=0.6 connection:keep-alive content-length:44 content-type:application/json;charset=utf-8 cookie:phpsessid=d5djbkgs7ttui073jl04mg6st3; __antixsrftoken=97b6e321343944a89ade4acc098305bd; asp.net_sessionid=2ggakcj1qxtewgsrh5qvtw40; _session_id=bah7b0kid3nlc3npb25faw....; .aspnet.applicationcookie=gcquqnfhbpax...; userpassword=password; username=admin; .aspxformsauth=7b15ee3de... dnt:1 host:localhost:52966 origin:http://localhost:52966 referer:http://localhost:52966/index.html user-agent:mozilla/5.0 (windows nt 6.3; wow64) applewebkit/537.36 (khtml, gecko) chrome/42.0.2311.135 safari/537.36 request payload view source {username: "admin", userpassword: "password"}

the question : why call login redirected? in method application_postauthorizerequest global.ascx.cs ai check context.request.isauthenticated , true.

the redirect comes configuration. have configured both loginurl , defaulturl. user sent before , after authentication respectively.


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -