0
How to implement a
custom IPrincipal in
ASP.NET MVC
Nat
20140224
Why ?


We want more user information in Principal object



Ex.


User.MemberID



User.LoginID
IPrincipal and IIdentity


System.Security.Principal.IPrincipal





Page.User

Controller.User

System.Security.Princ...
How


Define a class which implements IPrinicpal interface





Save custom settings to Cookie

Restore custom setting...
Implementation


public class CustomPrincipalSerializeModel



public class CustomPrincipal : IPrincipal



Signin – sa...
Implementation


Replace (User as CustomPrincipal).LoginID with User.LoginID



public class CustomController : Controll...
Implementation


Replace @(User as CustomPrincipal).MemberID With @(User.MemberID)



public abstract class CustomWebVie...
Reference


http://www.codeproject.com/Tips/574576/How-to-implement-a-customIPrincipal-in-ASP-NET-MV



http://stackover...
Upcoming SlideShare
Loading in...5
×

Implement custom iprincipal in mvc

862

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
862
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Implement custom iprincipal in mvc"

  1. 1. How to implement a custom IPrincipal in ASP.NET MVC Nat 20140224
  2. 2. Why ?  We want more user information in Principal object  Ex.  User.MemberID  User.LoginID
  3. 3. IPrincipal and IIdentity  System.Security.Principal.IPrincipal    Page.User Controller.User System.Security.Principal.IIdentity  User.Identity
  4. 4. How  Define a class which implements IPrinicpal interface    Save custom settings to Cookie Restore custom settings on every request Replace User object on PostAuthenticateRequest event
  5. 5. Implementation  public class CustomPrincipalSerializeModel  public class CustomPrincipal : IPrincipal  Signin – save custom settings   Login action Request – restore custom settings  Global.asax - Application_PostAuthenticateRequest
  6. 6. Implementation  Replace (User as CustomPrincipal).LoginID with User.LoginID  public class CustomController : Controller
  7. 7. Implementation  Replace @(User as CustomPrincipal).MemberID With @(User.MemberID)  public abstract class CustomWebViewPage : WebViewPage  public abstract class CustomWebViewPage<TModel> : WebViewPage<TModel>  Views/Web.config  <pages pageBaseType="CustomWebViewPage">
  8. 8. Reference  http://www.codeproject.com/Tips/574576/How-to-implement-a-customIPrincipal-in-ASP-NET-MV  http://stackoverflow.com/questions/1064271/asp-net-mvc-set-customiidentity-or-iprincipal
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×