1

I have a new MVC6 solution that uses ASP.Net Authentication and OAuth.

For my Account controller, I am able to retrieve the logged in Context.User.

However, I am not able to retrieve the same values when using another controller. Context.User.Identity fields all have null values.

How do I enable my other controller to retrieve the logged in user?

UPDATE: As mentioned in the comment trail in an answer below, the problem was in the client, not in the server, as the client was not sending the proper credentials for ASP.Net Authentication to identify.

Jonas Arcangel
  • 2,085
  • 11
  • 55
  • 85

1 Answers1

-1

First of all Microsoft merge Web API and MVC in MVC 6, so we can say there is no "WebAPI" anymore.

Maybe you are using MVC 5 and add the wrong tag? If that's the case maybe this or this can help you.

Community
  • 1
  • 1
Fagner Carvalho
  • 113
  • 1
  • 1
  • 9
  • I have corrected my post to not refer to WebAPI anymore. It is MVC6. – Jonas Arcangel Aug 10 '15 at 22:35
  • Can you add some code snippet to your original post? Considering no distinction between a API or MVC method I can't see how this is happening. – Fagner Carvalho Aug 10 '15 at 22:40
  • The problem I think lies in the client. I am calling my web service without a cookie and so it is not able to access the session. Now I need to figure out how to set "Microsoft.AspNet.Identity.Application" in my REST call. – Jonas Arcangel Aug 10 '15 at 23:21
  • Oh, I see! If you are accessing though a client like Fiddler you need to add a Cookie header in your request in the following format: `Cookie: .AspNet.Cookies=`. To retrieve this cookie you need to get the `Set-Cookie` header returned by your login action method. – Fagner Carvalho Aug 11 '15 at 01:51