asp.net mvc 3 - How can I access the logged in user from outside of a controller? -
I'm using Signal R to click on the client from my MVC3 application.
Every time a user clicks on something, I need to verify the logged-in user.
If it is inside an MVC3 controller, then I go:
if (User.Identity.IsAuthenticated) {String username = user.Identity.Name; // here my code} However, this code execution is not within a controller class.
Actually, how can I get a logged in user name from outside a controller?
Actually, how can I get a logged in user name from outside an administrator? ?
It depends on where you want to get access to them. If you do not have access to HttpContext you can always try HttpContext.Current.User and pray that it will not be blank for some reason For example that thread or something else is more likely to be with SignalRs which depends on the work and asynchronous processing. If this signal is within the center of R, then you have access to the user: public class chat: Hub {public void Foo () {string username = context.User.Identity.Name; }} Personally, I do not recommend using HttpContext.Current anytime. What you really are trying to achieve and I guarantee that there are better ways.
Comments
Post a Comment