IAuthorizationService Interface

[namespace: Serenity.Abstractions, assembly: Serenity.Core]

This is the interface that Serenity checks through to see if there is a logged user in current request.

  1. public interface IAuthorizationService
  2. {
  3. bool IsLoggedIn { get; }
  4. string Username { get; }
  5. }

Some basic implementation for web applications could be:

  1. using Serenity;
  2. using Serenity.Abstractions;
  3. public class MyAuthorizationService : IAuthorizationService
  4. {
  5. public bool IsLoggedIn
  6. {
  7. get { return !string.IsNullOrEmpty(Username); }
  8. }
  9. public string Username
  10. {
  11. get { return WebSecurityHelper.HttpContextUsername; }
  12. }
  13. }
  14. /// ...
  15. void Application_Start(object sender, EventArgs e)
  16. {
  17. Dependency.Resolve<IDependencyRegistrar>()
  18. .RegisterInstance(new MyAuthorizationService());
  19. }