asp.net mvc - How Request.IsAuthenticated work in mvc4 exactly -
i made 2 mvc project use login form before start use code login
public actionresult login(accountlog usr) { accountlog personindatabase = db.accountlogs.firstordefault(m => m.usercode == usr.usercode); formsauthentication.setauthcookie(personindatabase.username, true); viewbag.id = personindatabase.usersid; return redirecttoaction("main", "main");}
when run program @ check first if(request.isauthenticated)
if true return view if else redirect login page
public actionresult main() { if (request.isauthenticated) { return view(); } return redirecttoaction("login", "account"); }
it worked fine noticed if run first program , made success login , close not made logout , run second program not logged yet open logged person mean if made login first 1 , open second open fine , vise versa how can differentiate between 2 project login how can made alternative request.isauthenticated
if thing in question don't clear leave comment clear able me
from described trying login same application using same browser session in 2 different tabs without logging out first user.
when login success authentication cookie
set in browser. cookie sent server each time server can validate user.
as trying login ( or expect login) second tab using account, see first user logged in authentication cookie
account still persisted in browser. authentication cookie expire when user logs off.
so can either.
- test 2 accounts using 2 different browsers(e.g. chrome , firefox)
- log off first account before trying login using account in same browser.
hope helps!
Comments
Post a Comment