IAuthorizationService 接口

[命名空间: Serenity.Abstractions, 程序集: Serenity.Core]

这是 Serenity 通过检查当前请求判断用户是否已登录的接口。

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

对于 web 应用程序的一些基本实现可能是:

  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. }