Есть 3 класса, страница Login.aspx и Default.aspx | Код | public class MyMembership : MembershipBase, IHttpModule { #region IHttpModule Members private HttpApplication app;
public void Init(HttpApplication context) { this.app = context; //запрос на аутентификацию app.AuthenticateRequest += new EventHandler(app_AuthenticateRequest); //запрос на авторизацию app.AuthorizeRequest += new EventHandler(app_AuthorizeRequest); }
//запрос на аутентификацию void app_AuthenticateRequest(object sender, EventArgs e) { this.app = (HttpApplication)sender; HttpRequest request = HttpContext.Current.Request; HttpResponse responce = HttpContext.Current.Response;
//URL страницы для логина string loginUrl = Global.Setting.Security.LoginPage;
int a = request.Path.LastIndexOf("/"); //URL страницы, которая заправшивается string requestedUrl = request.Path.Substring(a + 1, request.Path.Length - (a + 1));
//ЧТО ТУТ НАДО ПИСАТЬ??????? МНЕ НЕ ПОНЯТНА ЛОГИКА, КОТОРУЮ НАДО РЕАЛИЗОВАТЬ!
// Ну а это уже понятно app.Context.User = principal;// - объект класса UserPrincipal
//Кстати, а это надо? System.Threading.Thread.CurrentPrincipal = principal;
}
//запрос на авторизацию void app_AuthorizeRequest(object sender, EventArgs e) { } }
|
| Код |
public class UserIdentity:System.Security.Principal.IIdentity { public UserIdentity() { // // TODO: Add constructor logic here // }
public UserIdentity(string userLogin) { this.Name = userLogin; this.IsAuthenticated = true; }
#region IIdentity Members
public string AuthenticationType { get { return "UserIdentity"; } }
public bool IsAuthenticated { get; set; }
public string Name { get; set; }
#endregion }
|
| Код |
public class UserPrincipal:System.Security.Principal.IPrincipal { private ArrayList _rolesList; public UserPrincipal() { }
public UserPrincipal(System.Security.Principal.IIdentity identity, ArrayList rolesList) { _rolesList = rolesList; this.Identity = identity; }
public bool IsInRole(string roleName) { return _rolesList.Contains(roleName); }
public System.Security.Principal.IIdentity Identity { get; set; } }
|
Ну вот я щелкнул на кнопке на Login.aspx, в 2-х TextBox'aх логин и пароль, а дальше то что? web.config | Код | <httpModules> <add name="MembershipModule" type="VanillaWind.BLL.Security.Membership"/> </httpModules>
|
|