开发者

Error while passing argument

I have a UserBll class which has following method

public string GetaspnetUserIdByUserName(string name )
{
    string _lsttUserId = (from aspnet in db.aspnet_Users
                            where aspnet.UserName.Equals(name)
                            select aspnet.UserId
                         ).ToString();
    return _lsttUserId;
}
开发者_如何学C

I create an instance of Usertable having UserId and UserName field and I am using following code

UserBLL bll = new UserBL
UserTable uTable = new UserTable();
uTable.UserId = bll.GetaspnetUserIdByUserName(Membership.GetUser(model.UserName));

in above code I get following error:

GetaspnetUserIdByUserName has some invalid argument

Can somebody please tell me what wrong I am doing


Membership.GetUser does not return a string, it returns a MembershipUser.

You want:

string username = Membership.GetUser(model.UserName).UserName;

In case you want to see whats going on:

MembershipUser theUser = Membership.GetUser(model.UserName);
string userName = theUser.UserName;


I think you mean to be calling the function like this:

UserBLL bll = new UserBL
UserTable uTable = new UserTable();
uTable.UserId = bll.GetaspnetUserIdByUserName(model.UserName);

Assuming that model.UserName is a string value.


The BLL function is needless.

MembershipUser user = Membership.GetUser("{your desired user name}");
UserTable uTable = new UserTable();
uTable.UserId = user.ProviderUserKey.ToString();

Because MembershipUser.ProviderUserKey == aspnet_User.UserId

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜