ASP.NET MVC / AX - 自定义成员资格提供程序

时间:2022-06-07 07:28:38

I am new to ASP.NET MVC Forms Authentication and have just started to create my own Custom Membership Provider. My ValidateUser and ChangePassword methods work but now I want to use the GetUser method to return the current user's data throughout my site. My AX method returns an AxaptaRecord which contains details of the user, like their phone number, company name etc.. How would I use this with the GetUser method?

我是ASP.NET MVC Forms Authentication的新手,刚刚开始创建自己的自定义成员资格提供程序。我的ValidateUser和ChangePassword方法有效但现在我想使用GetUser方法在我的网站中返回当前用户的数据。我的AX方法返回一个AxaptaRecord,其中包含用户的详细信息,例如他们的电话号码,公司名称等。我如何使用GetUser方法?

2 个解决方案

#1


1  

You just need to create a new instance of MembershipUser object and populate properties from the AxaptaRecord object, here is some pseudocode:

您只需要创建一个MembershipUser对象的新实例并从AxaptaRecord对象填充属性,这里有一些伪代码:

    MembershipUser user = new MembershipUser("AX",
    (string)axRecord.get_Field("name"),
    axRecord.get_Field("recid"),
    email, //get this from SysUserInfo table
    string.Empty,
    string.Empty,
    (bool)axRecord.get_Field("enable"),
    !(bool)axRecord.get_Field("enable"),
    (DateTime)Convert.ChangeType(axRecord.get_Field("createdDateTime"), typeof(DateTime)),
    DateTime.MinValue,
    DateTime.MinValue,
    DateTime.MinValue,
    DateTime.MinValue);

Then you return user from your GetUser method. See the GetUser method description here: http://msdn.microsoft.com/en-us/library/f1kyba5e.aspx

然后从GetUser方法返回用户。请参阅此处的GetUser方法说明:http://msdn.microsoft.com/en-us/library/f1kyba5e.aspx

#2


0  

Controller:

控制器:

var userDetails = System.Web.Security.Membership.GetUser(username);

Then, there are many different ways for you to pass the data to View. Each way has its advantage and disadvantage. For details, please click here.

然后,有许多不同的方法可以将数据传递给View。每种方式都有其优点和缺点。更多内容,请点击这里。

Model strongly-typed view can let you easily handle validation and generate data but not very good in display data if you have more than one table.

如果您有多个表,模型强类型视图可以让您轻松处理验证并生成数据,但不能很好地显示数据。

#1


1  

You just need to create a new instance of MembershipUser object and populate properties from the AxaptaRecord object, here is some pseudocode:

您只需要创建一个MembershipUser对象的新实例并从AxaptaRecord对象填充属性,这里有一些伪代码:

    MembershipUser user = new MembershipUser("AX",
    (string)axRecord.get_Field("name"),
    axRecord.get_Field("recid"),
    email, //get this from SysUserInfo table
    string.Empty,
    string.Empty,
    (bool)axRecord.get_Field("enable"),
    !(bool)axRecord.get_Field("enable"),
    (DateTime)Convert.ChangeType(axRecord.get_Field("createdDateTime"), typeof(DateTime)),
    DateTime.MinValue,
    DateTime.MinValue,
    DateTime.MinValue,
    DateTime.MinValue);

Then you return user from your GetUser method. See the GetUser method description here: http://msdn.microsoft.com/en-us/library/f1kyba5e.aspx

然后从GetUser方法返回用户。请参阅此处的GetUser方法说明:http://msdn.microsoft.com/en-us/library/f1kyba5e.aspx

#2


0  

Controller:

控制器:

var userDetails = System.Web.Security.Membership.GetUser(username);

Then, there are many different ways for you to pass the data to View. Each way has its advantage and disadvantage. For details, please click here.

然后,有许多不同的方法可以将数据传递给View。每种方式都有其优点和缺点。更多内容,请点击这里。

Model strongly-typed view can let you easily handle validation and generate data but not very good in display data if you have more than one table.

如果您有多个表,模型强类型视图可以让您轻松处理验证并生成数据,但不能很好地显示数据。