Implement custom iprincipal in mvc

  • 477 views
Uploaded on

 

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
477
On Slideshare
0
From Embeds
0
Number of Embeds
3

Actions

Shares
Downloads
2
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

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