لماذا User.Identity.IsAuthenticated كاذبة دائمًا؟


مرحباً جميعاً،
أريد الحصول على اسم المستخدم أدناه

<pre lang="c#">

 public ActionResult Login(LoginModel model, string returnUrl)
        {
 if (User.Identity.IsAuthenticated)//this is get always false
            {
string user = User.Identity.Name;//here i need username
            }
  
            if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password,     persistCookie: model.RememberMe))
            {
                return RedirectToLocal(returnUrl);
            }

            // If we got this far, something failed, redisplay form
            ModelState.AddModelError("", "The user name or password provided is incorrect.");
            return View(model);
        }

User.Identity.IsAuthenticated always return false so userid comes always -1, I am not even able to short out my mistake, what mistake am doing and how can i overcome with this, please help me.. 

الحل 1

لن يتم تعيين User.Identity.IsAuthenticated على “صحيح” حتى الطلب التالي بعد استدعاء FormsAuthentication.SetAuthCookie().

راجع http://msdn.microsoft.com/en-us/library/twk5762b.aspx

يضيف الأسلوب SetAuthCookie تذكرة مصادقة النماذج إلى مجموعة ملفات تعريف الارتباط أو إلى عنوان URL إذا كانت CookiesSupported خاطئة. توفر تذكرة مصادقة النماذج معلومات مصادقة النماذج للطلب التالي الذي يقدمه المتصفح.

الحل 2

مرحبًا بالجميع، كنت أختبر مصادقة حساب Microsoft باستخدام OWIN ولاحظ أنه يتعين عليك وضع التعليق التوضيحي للتفويض على الأقل في وحدة تحكم واحدة، وآمل أن يكون هذا مفيدًا

コメント

タイトルとURLをコピーしました