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
....
}