Search code examples
asp.net-mvc-3membership

Custom membership provider get current login user


I have little problem, I implement my own membership provider and it works fine. I added userid to articles by this code in controller:

[HttpPost, Authorize, ValidateInput(false)]
        public ActionResult Vytvorit(Article newArticle)
        {
            if(ModelState.IsValid){
                    if(!User.Identity.IsAuthenticated)
                    return View(newArticle);
                newArticle.User.UserID = (int)Membership.GetUser().ProviderUserKey;

            repo.Save(newArticle);
            return RedirectToAction("Zobrazit", new {id=newArticle.ArticleID});
            }
            return View(newArticle);
        }

and it was working but now after many changes (in another controllers, models and so) I tried and there is some problem with membership.getuser returns null.

I tried to google it and I found that there might be problem that authenticated user can't be found in the Membership datasource. But I dont know how to fix it.

Thanks

EDIT: MyMembershipProvider


Solution

  • Don't know if it will be much help but I found this to be a useful tutorial when putting together a custom membership provider recently.

    http://theintegrity.co.uk/2010/11/asp-net-mvc-2-custom-membership-provider-tutorial-part-1/