开发者

asp.Net MVC Add Properties to User class

开发者 https://www.devze.com 2023-03-07 15:58 出处:网络
In my app I want to add properties to the user class. How should I do it? My current solution is to create Users table in th database, but I just read that Asp.Net provides out-of-the-box users regis

In my app I want to add properties to the user class. How should I do it?

My current solution is to create Users table in th database, but I just read that Asp.Net provides out-of-the-box users registration API and funct开发者_运维问答ionality. How can I update the new properties?

Thank you


Do you mean you want a custom Principal? In that case you want to hook into the AuthenticateRequest method and add your own, derived principal. I recently answered a question regarding the creation of a custom principal here. While that question deals with WindowsAuthentication, the idea is the same:

  1. Get the current authenticated principal,
  2. use it to create your own custom principal,
  3. set your principal on the HttpContext and Thread.


You can write a custom Membership Provider that plugs into the membership & authorization features built into the framework. You can also write your own custom User class that inherits from the standard class. You can design it so that it uses your existing users table if you want.

This has worked out well for us on a couple different projects.

Here's some documentation: http://msdn.microsoft.com/en-us/library/f1kyba5e.aspx

0

精彩评论

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