0

ActiveDirectoryに対してフォーム認証を使用できるようにActiveDirectoryMembershipプロバイダーを実装しようとしています。

アプリケーションを参照して、サインインページにリダイレクトできます。間違ったパスワードを入力すると、正しいエラーが発生します。正しいパスワードを入力すると、デフォルトのURL(/Secure/Default.aspx)にリダイレクトされますが、すぐにサインインページにリダイレクトされます。私はフィドラーを使用しているので、2つのリダイレクトを見ることができます。したがって、ADに対して正しく認証されていることは確かですが、それでもサインインページに戻ります。また、アプリケーションでテストページを作成してそれを証明したため、ブラウザがCookieを受け入れることも知っています。以下にweb.configと関連するコードを含めましたが、何が欠けているのか理解できません...

編集: UseCookiesの代わりにUseUriを指定すると、すべてが機能し始めることがわかりました。しかし、あるページのCookieにデータを保存し、別のページでデータを取得できることを検証しました。それでは、なぜそれが認証部分で機能しないのでしょうか。

編集2 サインインページからコードを削除し、標準のログインコントロールを使用しました。同じ問題です。

Web.configファイル:

<connectionStrings>
    <add name="ADConnectionString" connectionString="LDAP://YNET" />
</connectionStrings>
<system.web>      
    <authentication mode="Forms">
      <forms name=".ASPXAUTH" 
             path="/FormsAuth"
             loginUrl="~/SignIn.aspx" 
             defaultUrl="~/Secure/Default.aspx" 
             timeout="20" 
             requireSSL="false"
             protection="All"
             slidingExpiration="true"
             cookieless="UseCookies"
             enableCrossAppRedirects="false"/>
    </authentication>

    <authorization>
      <!-- Deny unauthenticated users will cause automatic redirect to the sign in page when using forms authentication. -->
      <deny users="?"/>
      <allow users="*"/>
    </authorization>

    <!-- For non AD passthrough authentication, specify the defaultProvider property -->
    <membership defaultProvider="ActiveDirectoryMembershipProvider">
      <providers>
        <clear/>
        <add name="ActiveDirectoryMembershipProvider"
             type="System.Web.Security.ActiveDirectoryMembershipProvider"
             connectionStringName="ADConnectionString"
             attributeMapUsername="sAMAccountName"/>

       </providers>      
    </membership>
</system.web>

サインインページ:

bool bIsValid = System.Web.Security.Membership.ValidateUser(txtUsername.Text, txtPassword.Text);

//Authenticate the user credentials against the default membership provider specified in configuration
if (bIsValid)
{
    System.Web.Security.FormsAuthentication.SetAuthCookie(txtUsername.Text, true);

    System.Web.Security.FormsAuthentication.RedirectFromLoginPage(txtUsername.Text, true);

}
else
{
    //display error
    ....
}
4

1 に答える 1

1

Cookieの問題(およびおそらくログインの問題)は、Cookieのパスをに設定していることが原因です/FormsAuth。つまり、CookieはそのURLパスに対してのみ有効であり、それ以外の場合は破棄されます。また、<authorization>部分的なWeb.configの次の完全な更新で調整したので、セクションを少し調整することができます。

<connectionStrings>
    <add name="ADConnectionString" connectionString="LDAP://YNET" />
</connectionStrings>
<system.web>      
    <authentication mode="Forms">
      <forms name=".ASPXAUTH" 
             path="/"
             loginUrl="~/SignIn.aspx" 
             defaultUrl="~/Secure/Default.aspx" 
             timeout="20" 
             requireSSL="false"
             protection="All"
             slidingExpiration="true"
             cookieless="UseCookies"
             enableCrossAppRedirects="false"/>
    </authentication>

    <authorization>
      <allow users="*"/>
    </authorization>

    <!-- For non AD passthrough authentication, specify the defaultProvider property -->
    <membership defaultProvider="ActiveDirectoryMembershipProvider">
      <providers>
        <clear/>
        <add name="ActiveDirectoryMembershipProvider"
             type="System.Web.Security.ActiveDirectoryMembershipProvider"
             connectionStringName="ADConnectionString"
             attributeMapUsername="sAMAccountName"/>

       </providers>      
    </membership>
</system.web>
<location path="Secure">
    <system.web>
        <authorization>
            <deny users="?"/>
        </authorization>
    </system.web>
</location>

/Secureログインで保護したいフォルダが本当に唯一のフォルダである場合、上記は機能しますが、ログインページ以外のすべてをロックダウンしたい場合<deny users "?" />は、メイン<authorization>セクションで必要です。

于 2012-11-30T05:31:31.617 に答える