2017-07-14 18 views

回答

0

請參閱此鏈接:https://lbadri.wordpress.com/2014/11/23/reading-katana-cookie-authentication-middlewares-cookie-from-formsauthenticationmodule/

// Get Cookie 
var request = HttpContext.Request; 
var cookie = request.Cookies.Get(".AspNet.Cookies"); 
var ticket = cookie.Value; 

// Format Cookie to be converted 
ticket = ticket.Replace('-', '+').Replace('_', '/'); 
var padding = 3 - ((ticket.Length + 3) % 4); 
if (padding != 0) 
    ticket = ticket + new string('=', padding); 
var bytes = Convert.FromBase64String(ticket); 

// Decrypt 
bytes = System.Web.Security.MachineKey.Unprotect(bytes, 
    typeof(CookieAuthenticationMiddleware).FullName, 
    "Cookies", // See below 
    "v1"); 

通過字節參數後,取消保護參數,被稱爲目的,這需要預期的一個匹配,以便能夠正確解密。否則你會得到CryptographicException

的「曲奇」參數值相匹配:

(new CookieAuthenticationOptions()).AuthenticationType 

可以構建ClaimsIdentity在上面的鏈接解釋或轉儲字節的字符串解密後。

相關問題