开发者

Help with Membership.GetUser ASP.NET C#

I am given an error when I try to use Membership.GetUser. Using intellisense the .GetUser() just isn't there.... .AddMember() is. I'm already using System.Web.Security;

Neither of the two below are work开发者_StackOverflowing

   protected void Page_Load(object sender, EventArgs e)
    {

        string userName = User.Identity.Name;

        // Lets get the user's id
        Guid userId = (Guid)Membership.GetUser(userName).ProviderUserKey;

        MembershipUser user = Membership.GetUser(userName);
    }

Error

The type or namespace name 'GetUser' does not exist in the namespace (are you missing an assembly reference?)


This can be caused by a conflict with another class or folder in the project that is also called Membership. If you can't figure out what the underlying conflict is, you can usually work around it by spelling out the namespace (even though you're already using it).

Like so:

Guid userId = (Guid)System.Web.Security.Membership.GetUser(userName).ProviderUserKey;


Looks like you have named your page to Membership.aspx and so your code-behind class is named Membership i.e.

public partial class Membership : System.Web.UI.Page

Rename your page and it's code-behind class to avoid any side-wide confusion with built-in asp.net Membership class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜