简体   繁体   中英

Using Customized Membership in Asp.Net

I am using Asp.Net/C# in my application , I am using Asp.Net built-in membership framework .The installation of aspnet_regsql services have been properly installed on my database.The aspnet_users table however contains basic information about the user , How do I add additional information about a user.Should I modify the table itself or should I use another table and link it with aspnet_users table.Also the Membership.ValidateUser(username,password) works well , but I have a requirement where the login is based on the user code.How can I achieve this , is it possible with built-in Membership. Any suggestions are most welcome. Thanks

You can use the ProfileProvider ( ref ).

More info here: http://msdn.microsoft.com/en-us/library/2y3fs9xs.aspx

And here: How to assign Profile values?

Use an ASP.NET Profile-Provider instead.

http://www.4guysfromrolla.com/articles/101106-1.aspx

You can store any kind of additional information even binary(images). I've used The SqlProfileProvide myself in my current application to let the user himself select his startpage.

Therefor i just needed to add this to the web.config :

<profile defaultProvider="AspNetSqlProfileProvider">
  <providers>
    <clear/>
    <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="RM2ConnectionString" applicationName="/ERP"/>
  </providers>
  <properties>
    <add name="Startpage"/>
  </properties>
</profile>

And i could write this property in codebehind:

if(User.Identity.IsAuthenticated)
{
    HttpContext.Current.Profile.SetPropertyValue("Startpage", startPage); //startPage is a String
    HttpContext.Current.Profile.Save();
}

and read it in the following way:

if(User.Identity.IsAuthenticated)
{
    Dim user = Membership.GetUser();
    Dim startPage = HttpContext.Current.Profile.GetPropertyValue("Startpage") as String;
}

You can store anything you want, see the link above for further informations.

You could create a custom membership provider by inheriting from System.Web.Security.MembershipProvider - this way you can implement any additional functionality you need. You can then store the user details in your own table structure etc. You'd then point your web.config at your custom provider to use it.

Useful links:

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