0

まで認証されていない私は、この次のMVCアプリケーションを持っているユーザーが次のページ要求

Imはプロファイル値を割り当てるしようとすると問題がある:

FormsService.SignIn(model.Email、インサイド
  // Attempt to register the user 
      MembershipCreateStatus createStatus = MembershipService.CreateUser(model.Email, model.Password); 

      if (createStatus == MembershipCreateStatus.Success) 
      { 
       //Adding role 
       MembershipService.AddDefaultRole(model.Email); 

       FormsService.SignIn(model.Email, false /* createPersistentCookie */); 

       //Add other initial profile data 
       HttpContext.Profile["FirstName"] = model.FirstName; //PROBLEM 
       HttpContext.Profile["LastName"] = model.LastName; //PROBLEM 

       return RedirectToAction("List", new { area = "", controller = "Requests" }); 
      } 
      else 
      { 
       ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus)); 
      } 

)偽:

public void SignIn(string email, bool createPersistentCookie) 
    { 
     if (String.IsNullOrEmpty(email)) throw new ArgumentException("Value cannot be null or empty.", "email"); 

     FormsAuthentication.SetAuthCookie(email, createPersistentCookie); 
    } 

どうFormsAuthentication.SetAuthCookieを呼び出した後に来る、ユーザーがまだ認証されていませんか? エラーが発生しています。私は匿名ユーザーにいくつかのプロファイル値を割り当てようとしています。

答えて

1

クッキーを設定すると、レスポンスに追加されますが、IsAuthenticatedブールがリクエストから設定されます。認証を設定してセッション変数を設定したら、ホームページや元のリクエストなど別のページにリダイレクトする必要があります。

+0

これは意味があります。あなたは、次のリクエストの前にプロファイル値を更新する簡単な方法を知っていますか?値を一時的に保存して、次のページリクエストで保存する必要がありますか?それを行う正しい方法は何ですか? – Dhana

+0

する必要がありますか?あなたの初期化イベントで、ユーザーが認証されていてもプロファイル情報がない場合は、それをロードする時間だと思うでしょうが、私は内蔵プロファイルマネージャーを一度も使用していません。 –

関連する問題