0

I am trying to make a MVC application. In my _LoginPartial.cshtml,

I can use User.Identity.Name variable, which gives the username of current session, though any reference was specified otherwise. So, likewise, I thought User.Identity.Name would be also available in Global.asax, but it's not. My login system saves the username and password in cookie. Is there a way to recall the current username in Global.asax?

Tieson T.
  • 20,774
  • 6
  • 77
  • 92
user3734823
  • 99
  • 1
  • 1
  • 10
  • 1
    I don't understand why you cannot use `User.Identity.Name`? What error are you getting? I also wouldn't advise reading the username from a cookie. A cookie can easily be modified and they can then pretend to be another user. – Jamie Rees Jun 03 '15 at 15:33
  • User.Identity.Name works fine in my global.asax – ObedMarsh Jun 03 '15 at 15:34
  • Try using the full name, i.e.: HttpContext.Current.User.Identity.Name Wether you can use it or not in the global.asax file probably depends on *where* you want to use it, in what method. – HaukurHaf Jun 03 '15 at 15:34
  • I keep getting this error. an object reference is required for the nonstatic field method or property 'system.web.httpapplication.user.get' – user3734823 Jun 03 '15 at 15:40
  • @user3734823 Show us your code, but I think you are attempting to use an instance member from a static method, change your method to be non-static. – vcsjones Jun 03 '15 at 15:50
  • Btw [is-it-secure-to-store-passwords-in-cookies](http://stackoverflow.com/questions/2100356/is-it-secure-to-store-passwords-in-cookies) – Guillaume Beauvois Jun 03 '15 at 15:57

0 Answers0