Implement custom iprincipal in mvc
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Implement custom iprincipal in mvc

on

  • 578 views

 

Statistics

Views

Total Views
578
Views on SlideShare
555
Embed Views
23

Actions

Likes
0
Downloads
2
Comments
0

1 Embed 23

http://www.slideee.com 23

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Implement custom iprincipal in mvc Presentation Transcript

  • 1. How to implement a custom IPrincipal in ASP.NET MVC Nat 20140224
  • 2. Why ?  We want more user information in Principal object  Ex.  User.MemberID  User.LoginID
  • 3. IPrincipal and IIdentity  System.Security.Principal.IPrincipal    Page.User Controller.User System.Security.Principal.IIdentity  User.Identity
  • 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. Implementation  public class CustomPrincipalSerializeModel  public class CustomPrincipal : IPrincipal  Signin – save custom settings   Login action Request – restore custom settings  Global.asax - Application_PostAuthenticateRequest
  • 6. Implementation  Replace (User as CustomPrincipal).LoginID with User.LoginID  public class CustomController : Controller
  • 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. 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