0

ログイン フォームが にある Web アプリケーションがあり~/Account/Login.aspx、そこでログイン ロジックを実装しましたが、期待どおりに動作します。

今、私たちのグラフィック デザイナーは、ホームページの隅に小さな HTML ログイン フォームを配置して作り直しました。ホームページに別のログイン フォームを配置するというアイデアは気に入りましたが、このフォームを実際のログイン ページのように送信する方法がわかりません。実際のログイン ページの生成された html の内部を見てみましたが、イベントを使用していないようです。その<form>ため、入力ボックスの名前とフォーム アクションを実際のログインのものと一致するように調整することはできません。

コードビハインドをすべて書き直さずに、このログインフォームを有効にする方法はありますか?

4

1 に答える 1

1

ユーザーを認証するために、AJAX を使用してメンバーシップ サービスを呼び出すことができます。

AuthenticationServicesweb.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のコード ビハインドでログイン イベントを処理することです。

于 2012-09-25T19:25:04.420 に答える