मुझे सफल लॉगिन के बाद सीधे उपयोगकर्ता आईडी ग्रिड प्राप्त करने की आवश्यकता है। निम्नलिखित कोड काम नहीं करता:उपयोगकर्ता। Identity.Is प्रमाणीकृत सफल लॉगिन के बाद गलत है
if (Membership.ValidateUser(txtUsername.Value, txtPassword.Value))
{
FormsAuthentication.SignOut();
FormsAuthentication.SetAuthCookie(txtUsername.Value, true);
MembershipUser user = Membership.GetUser(txtUsername.Value);
if (user != null)
{
Guid puk = (Guid)user.ProviderUserKey;
}
}
इस क्यों होता है:
if (Membership.ValidateUser(txtUsername.Value, txtPassword.Value))
{
FormsAuthentication.SignOut();
FormsAuthentication.SetAuthCookie(txtUsername.Value, true);
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
// doesn't run
Guid puk = (Guid)Membership.GetUser().ProviderUserKey;
}
}
निम्नलिखित कोड काम करता है? SetAuthCookie
के अलावा क्या करने के लिए कुछ और है?
वहाँ एक ही अनुरोध में उपयोगकर्ता पहचान का उपयोग करने की कोई तरीका है? –
@ अहमद अहमदी आप इसे मैन्युअल रूप से कस्टम प्रिंसिपल ऑब्जेक्ट को HttpContext की उपयोगकर्ता प्रॉपर्टी को असाइन कर सकते हैं। –
@OleksiiAza क्या आप यह संभवतः यह दिखाने के लिए अपना उत्तर अपडेट कर सकते हैं कि यह कैसे करें? – Jake