User.Identity.Name blank in ASP.Net MVC

前端 未结 4 873
-上瘾入骨i
-上瘾入骨i 2020-12-11 00:45

Exactly as per the title.

Simply in my HomeController I have:

string Username = User.Identity.Name;

Why is this value always blank?

4条回答
  •  攒了一身酷
    2020-12-11 01:17

    Have you attached Authorize attribute to ur action or controller?

    public class HomeController : Controller {
        [Authorize]
        public ActionResult Index() {
             string userName = User.Identity.Name;
             return View();
        }
    }
    

提交回复
热议问题