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

Implement custom iprincipal in mvc

on

  • 511 views

 

Statistics

Views

Total Views
511
Views on SlideShare
488
Embed Views
23

Actions

Likes
0
Downloads
1
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 Implement custom iprincipal in mvc Presentation Transcript

  • 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.Principal.IIdentity  User.Identity
  • 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
  • Implementation  public class CustomPrincipalSerializeModel  public class CustomPrincipal : IPrincipal  Signin – save custom settings   Login action Request – restore custom settings  Global.asax - Application_PostAuthenticateRequest
  • Implementation  Replace (User as CustomPrincipal).LoginID with User.LoginID  public class CustomController : Controller
  • 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">
  • 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