2009-07-15 5 views
2

私はASP.NET MVC 1.0でAppを作成し、カスタムメソッド(管理者用)を使用してユーザーを作成したいと考えています。私はAccountメソッドのRegisterメソッドを使ってCreateメソッドに名前を変更しました。私はその後、行をコメントアウトしましたFormsAuth.SignIn(userName、false);新しく作成されたユーザーがサインインするのを避けるためMembershipService.CreateUser()をASP.NET MVCの自動ログインから停止する方法はありますか?

ユーザー作成フォームを完了すると、ユーザーはうまく追加されますが、サインインします。これで私と新しいユーザーがサインインされました。なぜならuser.IsOnlineのための私のListUsersのページのテスト

UPDATE(2009-07-15 14:40):私はいくつかのGoogleの-INGをやってuser.IsOnlineが原因ステートレスHTTPに非常に信頼性がないことが判明していますプロトコル。注:UserDetailsページ(MembershipUserAndRolesViewDataを使用して作成された)に移動した場合、Last LoginはNULLとして表示されます。しかし、私のListUsersページにはログイン日が表示されます... ???


public class AccountController : Controller 
{ 

// ... 

[Authorize(Roles = "Administrator")]  
[AcceptVerbs(HttpVerbs.Post)] 
     public ActionResult Create(string userName, string email, string password, string confirmPassword) 
     { 

      ViewData["PasswordLength"] = MembershipService.MinPasswordLength; 


      if (ValidateRegistration(userName, email, password, confirmPassword)) 
      { 

       // Attempt to register the user 
       MembershipCreateStatus createStatus = MembershipService.CreateUser(userName, password, email); 

       if (createStatus == MembershipCreateStatus.Success) 
       { 
        //FormsAuth.SignIn(userName, false); // createPersistentCookie 
        return RedirectToAction("ListUsers", "Account"); 
       } 
       else 
       { 
        ModelState.AddModelError("_FORM", ErrorCodeToString(createStatus)); 
       } 
      } 

      // If we got this far, something failed, redisplay form 
      return View(); 

     } 
} 

答えて

2

はこれを言及:現在の日付と時刻マイナスUserIsOnlineTimeWindowプロパティの値がユーザーのためにLastActivityDateよりも前である場合

ユーザーがオンラインと考えられています。

ユーザーのLastActivityDateは、CreateUser、UpdateUser、およびValidateUserメソッドによって現在の日付と時刻に更新され、GetUserメソッドのオーバーロードによって更新される可能性があります。

このページhttp://msdn.microsoft.com/en-us/library/system.web.security.membershipuser.lastactivitydate.aspxも、この意見:

ユーザーのためのLastActivityDateがでCreateUserとのvalidateUserの方法により、現在の日付と時刻に更新され、GetUserメソッドの一部のオーバーロードによって更新することができます。 UpdateUserメソッドを使用して、LastActivityDateプロパティを特定の日付と時刻に設定できます。

したがって、新しいアカウントを作成すると、これは「オンライン」とみなされます。 問題を回避するには、アカウントを作成するときに日付をリセットするAccountMembershipServiceクラスのデフォルトCreateUserを変更することができます

public MembershipCreateStatus CreateUser(string userName, string password, string email) 
    { 
     MembershipCreateStatus status; 
     MembershipUser user = _provider.CreateUser(userName, password, email, null, null, true, null, out status); 
     user.LastActivityDate = DateTime.MinValue; //set the LastActivityDate to a point far back in the past 
     _provider.UpdateUser(user); //update the user to the MembershipProvider 
     return status; 
    } 
0

表示していないコードに問題があります。既定のVSテンプレートを使用して新しいASP.NET MVCプロジェクトを作成し、FormsAuth.SignIn(userName, false)行をコメントアウトすると、ユーザーは期待どおりにサインインされません。

関連する問題