モノレールC#のログイン機能への良いリンクを教えてもらえますか?
私はモノレール C# の初心者で、ログイン機能を 1 つ実装する必要があります。
ありがとうございました。
メアレア
モノレールC#のログイン機能への良いリンクを教えてもらえますか?
私はモノレール C# の初心者で、ログイン機能を 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 メソッドを呼び出すだけだということです。