2015-09-30 5 views
5

मैं अपने आवेदन में प्रमाणीकरण (ओविन मिडलवेयर) के लिए एएसपीनेट पहचान 2.0 का उपयोग कर रहा हूं। सत्र अपहरण: जब मैं लॉगिन करता हूं पहचान पहचान AspNet.AplicationCookie.then, मैंने AspNet.AplicationCookie मान की प्रतिलिपि बनाई। तब मैंने एप्लिकेशन से लॉग आउट किया। लॉगआउट के बाद, मैं मैन्युअल रूप से कुकी बना रहा हूं (AspNet.AplicationCookie) और रीफ्रेश करें इसे रीडायरेक्ट करता है मुझे होम पेजविशेषाधिकार वृद्धि और सत्र में अपहरण एमवीसी 5

विशेषाधिकार वृद्धि: एक ही समय मैं के रूप में एक उपयोगकर्ता ऐ की नकल की (AspNet.ApplicationCookie) अपने कुकी में लॉग इन पर और मैं out.After लॉग इन मैं एक उपयोगकर्ता बीआई संपादन कर रहा हूँ उपयोगकर्ता B कुकी रूप में लॉग इन और चिपकाया उपयोगकर्ता A कुकी और इसे सेव किया। जब मैंने ब्राउजर को रीफ्रेश किया तो मैं यूजरए एक्सेस और प्रमाणीकरण प्राप्त कर सकता हूं।

मैं सभी सत्र साफ़ कर रहा हूं और सभी कुकीज़ को हटा रहा हूं जब मैंने लॉग आउट किया। Asp.Net पहचान (ओविन) भी नई AspNet उत्पन्न करता है। एप्लिकेशन हर बार कुकीज बनाता है। लेकिन फिर भी यह पुरानी कुकीज़ स्वीकार करता है और मुझे पहुंच प्रदान करता है मुझे नहीं पता क्यों? क्या कोई मुझे लॉग आउट करने के बाद पुराने AspNet.AplicationCookie को अमान्य कैसे कर सकता है। यह Startup.Auth.cs में मेरी कोड है

public void ConfigureAuth(IAppBuilder app) 
    { 
     // Enable the application to use a cookie to store information for the signed in user 
     app.UseCookieAuthentication(new CookieAuthenticationOptions 
     { 
      AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, 
      LoginPath = new PathString("/Account/Login") 
     }); 
     // Use a cookie to temporarily store information about a user logging in with a third party login provider 
     app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); 


    } 

// यह लॉगआउट कोड है

public ActionResult LogOff () 
    { 
     //Delete all cookies while user log out 
     string[] myCookies = Request.Cookies.AllKeys; 
     foreach (var cookies in myCookies) 
     { 
      Response.Cookies[ cookies ].Expires = DateTime.Now.AddDays(-1); 

     } 
     Request.GetOwinContext().Authentication.SignOut(Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ApplicationCookie); 

     // AuthenticationManager.SignOut(); 
     Session.Clear(); 
     Session.RemoveAll(); 
     Session.Abandon(); 
     return RedirectToAction("LoginPage", "Account"); 
    } 

// यह अपना लॉगिन नियंत्रक कोड है

public async Task<ActionResult> Login(LoginViewModel model, string returnUrl) 
    { 
     if (ModelState.IsValid) 
     { 
      var user = await UserManager.FindAsync(model.UserName, model.Password); 
      if (user != null) 
      { 
       await SignInAsync(user, model.RememberMe); 
       return RedirectToLocal(returnUrl); 
      } 
      else 
      { 
       ModelState.AddModelError("", "Invalid username or password."); 
      } 
     } 

     // If we got this far, something failed, redisplay form 
     return View(model); 
    } 

उत्तर

2

इस डिजाइन के द्वारा होता है । आपको कई ब्राउज़र से साइन-इन करने की अनुमति है और केवल उस ब्राउज़र में लॉग-आउट जहां आपने "लॉग-आउट" पर क्लिक किया है और अन्य सभी ब्राउज़रों पर क्लिक नहीं किया है।

लेकिन लॉग-आउट पर आप उपयोगकर्ता पर SecurityStamp अपडेट कर सकते हैं, और फिर बहुत कम समय के लिए सुरक्षा टिकट सत्यापन अवधि सेट अप कर सकते हैं।

इस सुरक्षा टिकट बदल जाएगा:

await userManager.UpdateSecurityStampAsync(user.Id); 

अपने लॉगआउट विधि में इस डाल दिया।

और अपनी Startup.Auth.cs इस तरह से UseCookieAuthentication संशोधित:

app.UseCookieAuthentication(new CookieAuthenticationOptions 
{ 
    AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, 
    LoginPath = new PathString("/Account/Login") 
    Provider = new CookieAuthenticationProvider 
    { 
     // Enables the application to validate the security stamp when the user logs in. 
     // This is a security feature which is used when you change a password or add an external login to your account. 
     OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
      validateInterval: TimeSpan.FromMinutes(1), // set this low enough to optimise between speed and DB performance 
      regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager)), 
    } 
});    

इस दृष्टिकोण के साथ केवल दोष यह है - जब लॉगआउट प्रक्रिया निष्पादित नहीं कर रहा है - कुछ नहीं होता। और जब लॉगआउट होता है, तो यह अन्य सभी सत्रों को लॉग करता है।

संबंधित मुद्दे