ユーザーを認証するために、AJAX を使用してメンバーシップ サービスを呼び出すことができます。
AuthenticationServices
web.config ファイルでを有効にする必要があります。
<configuration>
<system.web.extensions>
<scripting>
<scriptResourceHandler enableCaching="false" enableCompression="false" />
<webServices>
<authenticationService enabled="true" requireSSL="false" />
</webServices>
</scripting>
</system.web.extensions>
</configuration>
そして、ページで:
<form id="form1" runat="server">
<div>
<asp:ScriptManager runat="server" ID="sm">
</asp:ScriptManager>
<asp:LoginView runat="server">
<AnonymousTemplate>
<input type="tel" name="user" id="user" />
<br />
<input type="password" name="pass" id="pass" />
<br />
<input type="button" value="Login" name="login" id="login" onclick="attemptLogin(this);" />
</AnonymousTemplate>
<LoggedInTemplate>
<input type="button" name="logout" id="logout" value="Logout" onclick="attemptLogout(this);" />
</LoggedInTemplate>
</asp:LoginView>
<asp:LoginName FormatString="Welcome {0}!" runat="server" />
<%--<asp:LoginStatus runat="server" />--%>
</div>
<script>
function attemptLogin(e) {
Sys.Services.AuthenticationService.login(
$get("user").value,
$get("pass").value,
false,
null,
null,
function success(validCredentials, userContext, methodName) {
if (validCredentials == true) {
alert("user logged in");
window.location = window.location;
}
else {
alert("user name or password incorrect");
}
}, function fail(error, userContext, methodName) {
alert(error.get_message());
}, null);
}
function attemptLogout(e) {
Sys.Services.AuthenticationService.logout(
window.location,
null,
null,
null
);
}
</script>
</form>
AuthenticationService
または、 AJAX を使用する代わりに、ログイン ロジックを使用して Web サービスを公開し、その Web サービスを呼び出すこともできます。
もう 1 つの方法はUserControl
、ログイン コントロールを使用して を作成し、そのコントロールをホーム ページに配置して、UserControl
のコード ビハインドでログイン イベントを処理することです。