locked
problem (Guid)Membership.GetUser(User.Identity.Name).ProviderUserKey object not found RRS feed

  • Question

  • User-357604746 posted

    Hi,

    I'm looking for solution about my problem but I can't found and I do not have any idea.

    My problem:
    I have one the same application (in the same folder D:\MyApp)

    Binding more domain name (domain1, domain2, domain3,...)

    When I login in domain1 always is ok, but when I login in domain2, I got object not found: (Guid)Membership.GetUser(User.Identity.Name).ProviderUserKey

    In this case still shows (I was trying only for test): Button1.Text = Membership.ApplicationName; and shows applicationname

    Pls help



    Sunday, February 1, 2015 8:02 AM

All replies

  • User465171450 posted

    It shouldn't matter if you specified an application name because the web application uses the application name defined in the web.config.

    Has the user logged into other domains? Keep in mind, the forms authentication cookie is sent out for the domain the user logged into. You go to another domain, there is no cookie for that domain that contains forms authentication information. The User.Identity.Name will most likely return the IIS_IUSR account. Have you tried visiting the other bound domain and logging in and then determining if this code fails?

    Also, it's not good practice to use ProviderUserKey immediately. You should get a user, test for null, then handle it otherwise you are prone to these errors and miss chances to handle/log them properly.

    Sunday, February 1, 2015 9:24 AM
  • User-357604746 posted

    Hi,

      var membershipuser = Membership.Providers["AspNetSqlMembershipProvider"];
                membershipuser.ApplicationName = baseUrl();
    
    
                if (membershipuser.ValidateUser(username, pass) && (rolesuser.Count() == 0) || (membershipuser.ValidateUser(username, pass) && (rolesuser.FirstOrDefault().RoleId == new Guid("94A8F133-0C01-47BB-AB33-3E6D640D5DD9"))))
                {

    Applicationname I have defined when user login.


    Problem is if user is login in the same application working, but if user login in other application not working. returns error:


    Applicationname=domainname

    domain1
    domain2


    Users who is login in domain1 working,

    If users login in domain2... not working and returns object not found.

    I have in one IIS 7.0 created one directory and one path for application.







    Sunday, February 1, 2015 9:59 AM
  • User-357604746 posted

    For this I need use custom login and add Session["ProviderUserKey"] = (from t1 in db.aspnet_Users where t1.UserName == UserName.Text.Trim() select t1.UserId).FirstOrDefault();

    Code:

       var membershipuser = Membership.Providers["AspNetSqlMembershipProvider"];
                membershipuser.ApplicationName = baseUrl();
    
                if (Membership.ValidateUser(username, pass))
                {
    
                    if (Request.QueryString["ReturnUrl"] != null)
                    {
    
                       // FormsAuthentication.RedirectToLoginPage();
    
                    }
    
                    else
                    {
                        Session["ProviderUserKey"] = (from t1 in db.aspnet_Users where t1.UserName == UserName.Text.Trim() select t1.UserId).FirstOrDefault();
                       // FormsAuthentication.SetAuthCookie(username, false,UserName.Text.Trim());
    
                     //   Response.Redirect("test-login.aspx");
    
                        //Response.Redirect("~");
    
                    }

    Really not exists simple code or need create own session or cookies for my example?

    Sunday, February 1, 2015 11:18 AM
  • User-1151753377 posted

    Hi mmrat,

    Thank you for your post.

    Problem is if user is login in the same application working, but if user login in other application not working. returns error:

    Please confirm that the configuration is correct in the two application.

    Tuesday, February 3, 2015 1:04 AM