I realize this question might seem trivial to some, but it's these types of things that I find myself fighting with quite a bit and I just want to make sense of it all despite that seeming to be a losing battle in .net (for me anyway).
So, if I do the following:
using System.Web;
...
ApplicationUser user = System.Web.HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>().FindById(System.Web.HttpContext.User.Identity.GetUserId());
That produces the error in the title and a red GetOwinContext()
and the error Cannot resolve symbol 'GetOwinContext()'
However, if I do the following (remove System.Web
from in front of HttpContext
), it works as expected (or at least no errors):
using System.Web;
...
ApplicationUser user = HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>().FindById(System.Web.HttpContext.User.Identity.GetUserId());
However, if I do this (same line that's working with using System.Web
commented out):
//using System.Web;
...
ApplicationUser user = HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>().FindById(System.Web.HttpContext.User.Identity.GetUserId());
It produces the same red GetOwinContext()
and the error Cannot resolve symbol 'GetOwinContext()'
If I google HttpContext
I can only find that it stems from System.Web
.
So, the question is why can't I use the full syntax like in the first example above? (Also mentioned in the answer here with the highest votes: ASP.NET MVC 5 - Identity. How to get current ApplicationUser)
UPDATE (to address duplicate question reply): While there is an answer on that question that may come to the same conclusion, I don't really understand how this is a duplicate question. Try to think of it from a newbie perspective and dissecting all the smoke and mirrors that is .Net. I have never tried to learn something so convoluted in my life as .Net and sometimes you have to look at things from many different angles.
I actually saw that question and one other regarding using Current,
but neither struck me as 1) being the answer I was looking for (at the time) 2) more importantly, why it's behaving like that. Sam's answer is perfect, although a bit over my head. But, at least now, I can go research what it all means...