2011-10-11 26 views
9

Aşağıdaki iletiler, Karma Mod Kimlik Doğrulaması'nı kullanarak bir site için web.config dosyasının nasıl kurulacağını gösterir. IIS7 Mixed Mode Authentication ve How to allow mixed-mode authentication in IIS 7.0.ASP.NET ile karma mod kimlik doğrulaması kullanırken IIS7 nasıl yapılandırılır

Sitemi kurdum ve yerel olarak çalışıyorum (geliştirici makinemde). Ancak, sunucuda yerel olarak çalıştırdığımda 401.2 olsun - Giriş sunucu yapılandırma hatası nedeniyle başarısız oldu.

Sunucu, Varsayılan Web Sitesi ve Sitemi nasıl yapılandırmam gerektiğini herkes biliyor mu?

Düzenleme: İşte burada, form kimlik doğrulama düğümünden loginUrl dahil web.config'deki ayarlar.

<location path="~/Account/WinLogin.aspx"> 
    <system.web> 
     <authorization> 
     <deny users="?"/> 
     <allow users="*"/> 
     </authorization> 
    </system.web> 
    <system.webServer> 
     <security> 
     <authentication> 
      <anonymousAuthentication enabled="false"/> 
      <windowsAuthentication enabled="true"/> 
     </authentication> 
     </security> 
    </system.webServer> 
    </location> 
    <system.web> 
    <authentication mode="Forms"> 
     <forms loginUrl="~/Account/WinLogin.aspx" timeout="60"/> 
    </authentication> 
    <authorization> 
     <deny users="?"/> 
    </authorization> 

cevap

11

en çıkaracaksın

pencere kimlik doğrulama ve anonim auth bölümler etkin/yüklü olduğundan emin olmak için, (bu sunucu yöneticisi, roller, IIS altında) ve sunucu rolleri yapılandırması ile başlayalım Ayrıca, formları (zaten sahip olduğunuz).

<configuration> 
    <system.web> 
    <authentication mode="Forms"> 
     <forms cookieless="UseDeviceProfile" defaultUrl="~/Default.aspx" enableCrossAppRedirects="true" loginUrl="~/WindowsLogin.aspx" name=".ASPXAUTH" path="/" protection="All" requireSSL="false" slidingExpiration="true" timeout="10080"/> 
    </authentication> 
    <authorization> 
     <deny users="?"/> 
    </authorization> 
    </system.web> 
    <location path="Login.aspx"> 
     <system.web> 
      <authorization> 
       <allow users="?"/> 
      </authorization> 
     </system.web> 
     <system.webServer> 
      <security> 
       <authentication> 
        <anonymousAuthentication enabled="true"/> 
        <windowsAuthentication enabled="false"/> 
       </authentication> 
      </security> 
     </system.webServer> 
    </location> 
    <location path="WindowsLogin.aspx"> 
     <system.web> 
      <authorization> 
       <deny users="?"/> 
       <allow users="*"/> 
      </authorization> 
     </system.web> 
     <system.webServer> 
      <security> 
       <authentication> 
        <anonymousAuthentication enabled="false"/> 
        <windowsAuthentication enabled="true"/> 
       </authentication> 
      </security> 
     </system.webServer> 
    </location> 
</configuration> 

Sonra edeceğiz: Aşağıdaki bölüm tanımlanmıştır etmek istiyorum gidiyoruz web.config

: yüklendikten sonra bunların/yapılandırılmış, aşağıdaki malzeme tanımlamak gerekir iki dosyayı gerekir:

Login.aspx (this does forms auth) 
WindowsLogin.aspx (this does Windows auth) 

GİRİŞ doğru, formları yapar, bu sadece bataklık oluyor böylece standart ASP.NET kimlik doğrulama oluşturan o (bu dosyayı ve burada)

büyü yaptığı WindowsLogin var
using System; 
using System.Web; 
using System.Web.Security; 
using App_Code.Biz; 

public partial class WindowsLogin : System.Web.UI.Page { 
    protected string UserIsInRoles = string.Empty; 
    private static readonly BAL _mBAL = new BAL(); 
    protected void Page_Load(object sender, EventArgs e) { 
     string redirectUrl = Request["returnurl"] ?? "~/default.aspx"; 
     string username = Request.ServerVariables["LOGON_USER"]; 
     try { 
      if (Roles.GetRolesForUser(username).Length < 1) 
       Roles.AddUserToRole(username, Global.defaultRole); 
      int status; 
      _mBAL.aspnet_Membership_CreateUser(username, out status); 
     } catch (Exception ex) { 
      ErrHandler.WriteXML(ex); 
     } 

     /* Test to see if the user is in any roles */ 
     if (Roles.GetRolesForUser(username).Length < 1) { 
      UserIsInRoles = "<br />" + username + "You are not in any rules. This must be your first visit to our site!<br /> Adding you to the " + Global.defaultRole + " role now!"; 

     } else { 
      UserIsInRoles = "You are in the following roles: "; 
      string[] roles = Roles.GetRolesForUser(username); 
      foreach (string role in roles) 
       UserIsInRoles += role + ", "; 
      UserIsInRoles = UserIsInRoles.Remove(UserIsInRoles.Length - 2) + "!"; 

      if (Login(username, String.Join(",", roles))) 
       Response.Redirect(redirectUrl); 
     } 

     //we shouldn't get here, so if we do, redirect back to a page they can use. 
     if (Page.IsPostBack) { 
      if (Response.StatusCode == 401) 
       Response.Redirect("~/Login.aspx"); 

     } 
    } 

    private bool Login(string strUser, string strRole) { 
     if (strRole != null) { 
      FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
       1,       // version 
       strUser,      // user name 
       DateTime.Now,     // create time 
       DateTime.Now.AddYears(1),  // expire time 
       false,      // persistent 
       strRole);      // user data 
      string strEncryptedTicket = FormsAuthentication.Encrypt(ticket); 
      HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, strEncryptedTicket); 
      Context.Response.Cookies.Add(cookie); 
      return true; 
     } 
     return false; 
    } 
} 

Tüm bunlardan sonra, üst düzeyde kilitli bölüm için bir yapılandırma hatası alabilirsiniz. Kilit, varsayılan olarak (overrideModeDefault = "Reddet") veya açıkça bir konum etiketiyle ayarlanır ... ve eğer öyleyse, düzeltmenin en hızlı yolu C: \ Windows \ System32 \ inetsrv \ config \ applicationHost.config ve şu bloğu düzenleyin: http://chat.stackoverflow.com/rooms/5/conversation/configuring-iis7-and-mixed-mode-authentication-in-asp-net

+0

en sonunda Kilit hatası dahil açıklandığı gibi bu tam olarak dışarı oynanan:

<configSections> <sectionGroup name="system.webServer"> <sectionGroup name="security"> <sectionGroup name="authentication"> <section name="anonymousAuthentication" overrideModeDefault="Allow"> <section name="windowsAuthentication" overrideModeDefault="Allow"> </sectionGroup> </sectionGroup> </sectionGroup> </configSections> 

Ayrıca sohbet günlüğüne bakın. Önerilen "düzeltmenin" sonuçlarından endişeleniyorum. Varsayılan davranışı bu şekilde geçersiz kılarak bazı güvenlik açıklarını veya olası sorunları açıyor muyum? Bir hack gibi hissettiriyor. Bu çok eski ... Şimdi daha iyi bir yol var mı acaba? – ctb

+0

Microsoft, güvenlik önlemi olarak varsayılan olarak reddediyor. IIS metatabanını varsayılan olarak düzenleyen her şey, bir kesmek gibi hissettirir. Bunu değiştirmene izin vermek için muhtemelen bir UI işlevi var ama nerede olduğunu bulmak için açılamam. – jcolebrand

+0

İlk önce ( – jcolebrand

İlgili konular