Click here to Skip to main content
14,240,435 members
Rate this:
Please Sign up or sign in to vote.
I am trying to learn Angular2

and I am trying to create a simple blog with authentication.

this here is my add a new post method:

[Authorize]
// POST: api/Post
public PostModel Post([FromBody]PostViewModel model)
{             
    var post = new PostModel
    {
        Body = model.Body,
        Title = model.Title,
        AuthorId = IdentityExtensions.GetUserId(User.Identity),
    };
    var res = blogRepo.AddPost(post);
    return res;                 
}

everything works fine, but
IdentityExtension.GetUserId()
do not return the most current logged in user but the first user since the app started.

basically I am looking for a way to make sure that the current user logs out on the server as well as on the client (the client side is just a simple removal of the localStorage.removeItem("jwt");)

also there is a good chance that what I am doing is totally wrong, but I can't access the ApplicationUserManager in this controller.

What I have tried:

best res so far was:
AuthorId = IdentityExtensions.GetUserId(User.Identity)
also
Request.GetOwinContext().Authentication.SignOut();

this last one basically i tried to make a logout method, but I cant call this method for what ever the reasons
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100