简体   繁体   中英

Problems in aspnet membership provider

I am using asp.net memebership

I log out the applcation by writting this code for log out

if (Membership.GetUser(HttpContext.Current.User.Identity).IsOnline) ;
{
    FormsAuthentication.SignOut();

    Response.Redirect(FormsAuthentication.LoginUrl);
}
Response.Redirect("loginpage.aspx");

After then I started the application and gettig the error in code block of authetication .below I am writtng a code and error message

else if (User.Identity.IsAuthenticated == true && Membership.GetUser( Membership.FindUsersByName(User.Identity.Name)).IsOnline==true)
{
    FormsAuthentication.SignOut();
    FormsAuthentication.RedirectToLoginPage();
    MembershipUser currUser = null;

    string gt = null;
    if (HttpContext.Current.User != null)
    {
        currUser = Membership.GetUser(true);
        gt = currUser.Email;
    }

    /// string temp = User.Identity.GetProfile().ID;
    //string query = "Insert into user_tbl(MemberID)(" + temp + ")";
    //Response.Redirect("UserPanel.aspx");
    //return;
}

here Membership.FindUsersByName(User.Identity.Name)).IsOnline==true) I am getting this error

[ArgumentException: The provider user key supplied is invalid. It must be of type System.Guid. Parameter name: providerUserKey]

I am unable to find what to do , I debug the application and found User.Identity.Name as a hash value

Stack Trace 
Exception Details: System.ArgumentException: The provider user key supplied is invalid.  It must be of type System.Guid.
Parameter name: providerUserKey

Source Error: 


Line 86:             }
Line 87: 
Line 88:             else if (User.Identity.IsAuthenticated == true && Membership.GetUser( Membership.FindUsersByName(User.Identity.Name)).IsOnline==true)
Line 89:             {
Line 90:                 

Source File: d:\31 May 2012\Demo\LoginPage.aspx.cs    Line: 88 

Stack Trace: 


[ArgumentException: The provider user key supplied is invalid.  It must be of type System.Guid.
Parameter name: providerUserKey]
   System.Web.Security.SqlMembershipProvider.GetUser(Object providerUserKey, Boolean userIsOnline) +2242996
   System.Web.Security.Membership.GetUser(Object providerUserKey, Boolean userIsOnline) +40
   System.Web.Security.Membership.GetUser(Object providerUserKey) +6
   LoginPage.Page_Load(Object sender, EventArgs e) in d:\31 May 2012\Demo\LoginPage.aspx.cs:88
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +36
   System.Web.UI.Control.OnLoad(EventArgs e) +92
   System.Web.UI.Control.LoadRecursive() +54
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772

或者,您也可以使用Request.IsAuthenticated,哪个获取整个用户对象并仅检查身份验证。

According to Visual Studio, Membership.FindUsersByName returns MembershipUserCollection. You pass that object to the Membership.GetUser method, which does accept a parameter of the object type, but that object is supposed to be a user's ID (a GUID in ASP.NET). So, the exception is quite expected: you're trying to pass a collection of users, while the method expects a single user ID.

If you need to check whether a user is currently logged in, you can simply do this:

if (Membership.GetUser() != null)

See this MSDN Library article for more information on the method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM