Авторизация в ASP.Net - CodeHelper

Авторизация в ASP.Net

2

Как объединить Windows и Forms(Custom) аунтификацию?

Лучший ответ:

2

Есть хорошая статья по этому поводу, но на английском: Mixing Forms and Windows Security in ASP.NET. Там же есть рабочий пример ASP.NET-сайта.

Новые ответы

Новые Лучшие

0

Вот ещё неплохое решение для объединения разных видов авторизаций

public class Login : Page {
  protected Label ErrorMessageLabel; 
  protected TextBox UsernameTextBox; 
  protected TextBox PasswordTextBox; 
  protected CheckBox CheckBox1; 

  public void Page_Load(object o, EventArgs e) {
    if (IsPostBack) {
      string authenticatedUser = null; 
      if (CheckBox1.Checked) // Use their network credentials 
      {
        string user = Request.ServerVariables["LOGON_USER"];
        if (user.Length == 0) // They haven't provided credentials yet
        { 
          Response.StatusCode = 401;
          Response.StatusDescription = "Unauthorized";
          Response.End(); 
        }
        else // They have
        {
          authenticatedUser = user; 
        }
      }
      else // Use the username and password they provide
      {
         if (IsPasswordOK(UsernameTextBox.Text, PasswordTextBox.Text)) {
          authenticatedUser = UsernameTextBox.Text; 
        }
      }
      if (authenticatedUser != null) // They authenticated successfully
      {
        // Issue the Forms Auth cookie and send them on their way
        FormsAuthentication.RedirectFromLoginPage(authenticatedUser, false);
      }
      else // They didn't
      {
        ErrorMessageLabel.Text = "Invalid username or bad password. Please try again."; 
      }
    }
  }
}

v1.7.123.556
© 2009—2010 CodeHelper FAQ | О сайте | Обратная связь | История изменений | Статьи
Creative Commons LicenseМатериалы сайта распространяются под лицензией Creative Commons Attribution-Share Alike 3.0 Unported.