2017-01-17 14 views
0

私はフォームベース認証を使用するアプリケーションを持っています。私は以前これを使ったことがありません。Forms AuthetnicationはIISでフォーム認証を無効にして動作します

private bool ValidateUser(string userName, string password, string strConnectionString) 
     { 
      SqlConnection conn; 
      SqlCommand cmd; 
      string lookupPassword = null; 

      // Check for invalid userName. 
      // userName must not be null and must be between 1 and 15 characters. 
      if ((null == userName) || (0 == userName.Length) || (userName.Length > 15)) 
      { 
       System.Diagnostics.Trace.WriteLine("[ValidateUser] Input validation of userName failed."); 
       return false; 
      } 

      // Check for invalid passWord. 
      // passWord must not be null and must be between 1 and 25 characters. 
      if ((null == passWord) || (0 == passWord.Length) || (passWord.Length > 25)) 
      { 
       System.Diagnostics.Trace.WriteLine("[ValidateUser] Input validation of passWord failed."); 
       return false; 
      } 

      try 
      { 
       // Consult with your SQL Server administrator for an appropriate connection 
       // string to use to connect to your local SQL Server. 
       //conn = new SqlConnection(connectionstringremoved); 
       conn = new SqlConnection(strConnectionString) 

       conn.Open(); 
       Error.Text = "Got here"; 

       // Create SqlCommand to select pwd field from users table given supplied userName. 
       cmd = new SqlCommand("Select pwd from users where [email protected]", conn); 
       cmd.Parameters.Add("@userName", SqlDbType.VarChar, 25); 
       cmd.Parameters["@userName"].Value = userName; 

       // Execute command and fetch pwd field into lookupPassword string. 
       lookupPassword = (string)cmd.ExecuteScalar(); 

       // Cleanup command and connection objects. 
       cmd.Dispose(); 
       conn.Dispose(); 
      } 
      catch (Exception ex) 
      { 
       // Add error handling here for debugging. 
       // This error message should not be sent back to the caller. 
       System.Diagnostics.Trace.WriteLine("[ValidateUser] Exception " + ex.ToString()); 
       Error.Text = ex.ToString(); 

      } 

      // If no password found, return false. 
      if (null == lookupPassword) 
      { 
       // You could write failed login attempts here to event log for additional security. 
       return false; 
      } 

      // Compare lookupPassword and input passWord, using a case-sensitive comparison. 
      return (0 == string.Compare(lookupPassword, passWord, false)); 

     } 

私はIIS 6.1には、このアプリケーションを公開していると私はそれに関係なく、フォーム認証が有効になっているかどうかにない働くことに気づいた(それは、以下の場合には無効になっています):ここではサンプルのサンプルコードです。

enter image description here

私は基本認証についても同じ疑問を持っています。

匿名認証が有効になっていると考えられます。つまり、匿名認証を有効にすると、デフォルトでフォーム認証が有効になります。しかし、私はこの声明を支持するいかなる文書も見つけることができません。

答えて

0

匿名認証が有効になっています。

匿名認証はで皆を許可するよう

+0

私はフォーム認証を有効にすると、エラーが発生している。これは、効果的に、あなたがNO認証を持っていないことを意味します。要求フィルターモジュールは、クエリ要求を拒否するように設定されています文字列が長すぎます。これは404.15ページの応答です。 – w0051977

+0

これは、フォーム認証が実際に機能し、フォーム認証を有効にするかどうかに関係なく機能しなくなることを示しています。だから次の段階に進み、404.15ページの回答をどうやって回避するかを考えなければなりません... –

関連する問題