1

モノレールC#のログイン機能への良いリンクを教えてもらえますか?

私はモノレール C# の初心者で、ログイン機能を 1 つ実装する必要があります。

ありがとうございました。

メアレア

4

2 に答える 2

1

これがAyendeRahienからのものです

于 2009-11-07T00:22:17.267 に答える
1

Ayende のソリューションと同様に、最善の方法は、ASP.net 認証メカニズムを使用することです。LoginController でのアクションの例を次に示します。

        [AccessibleThrough(Verb.Post)]
    public void Authenticate(string username, string password, bool autoLogin, string returlUrl)
    {
        SomeWebServiceAuthenticationProvider wsSecurity = new SomeWebServiceAuthenticationProvider();


        bool isValid = wsSecurity.ValidateUser(username, password);

        if (isValid)
        {
            //first perform a logout to make sure all other cookies are cleared
            InternalLogout();

            FormsAuthentication.SetAuthCookie(username, autoLogin);
            PropertyBag["username"] = username;
            PropertyBag["password"] = password;
            PropertyBag["autoLogin"] = autoLogin;

            //redirect back to the Home page, or some other page
            if (!RedirectToPreviousUrl()) Redirect("home", "index");
        }
        else
        {
            Flash["auth_error"] = "Invalid user name or password.";
            RedirectToAction("Index");
        }
    }

「SomeWebServiceAuthenticationProvider」の代わりに他の認証メカニズムを代用できます...ここでのポイントは、標準の FormsAuthentication メソッドを呼び出すだけだということです。

于 2010-01-14T19:31:44.307 に答える