これは今まで見たことがなく、困惑しています。次のコントローラーシーケンスがあります。
/// <summary>
/// Helper method to store offerId to TempData
/// </summary>
/// <param name="offerId"></param>
private void StoreOfferInTempData(string offerId)
{
if (TempData.ContainsKey(SelectedOfferKey))
TempData.Remove(SelectedOfferKey);
TempData.Add(SelectedOfferKey, offerId);
}
[HttpPost]
[AllowAnonymous]
public virtual ActionResult Step1(MyViewModel model)
{
if (ModelState.IsValid)
{
StoreOfferInTempData(model.SelectedOfferId);
return RedirectToAction(MVC.Subscription.Register());
}
MySecondViewModel model2 = new MySecondViewModel { OfferId = model.SelectedOfferId };
return View(model2);
}
[HttpGet]
[AllowAnonymous]
public virtual ActionResult Register()
{
string offerId = TempData[SelectedOfferKey] as string; //we get a valid value here
... error handling content elided ...
RegisterViewModel model = new RegisterViewModel { OfferId = offerId };
return View(model);
}
[HttpPost]
[AllowAnonymous]
public virtual ActionResult Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
CreateCustomerResult result = CustomerService.CreateAccount(model.Email, model.NewPassword);
if (result.Success)
{
... content elided; storing customer to Session ...
MyMembershipProvider.PersistUserCookie(result.Principal, true);
//need to store our selected OfferId again for use by the next step
StoreOfferInTempData(model.OfferId);
return RedirectToAction(MVC.Subscription.Payment());
}
model.ErrorMessage = result.ErrorMessage;
}
return View(model);
}
[HttpGet]
public ActionResult Payment()
{
string offerId = TempData[SelectedOfferKey] as string; //this is null???
... content elided ...
return View(model);
}
TempData へのストレージの最初のラウンドは、期待どおりに動作します。値は後続の HttpGet メソッドに存在し、再度追加しようとすると削除されるようにマークされます。ただし、3 番目の HttpGet メソッドでは、null が返されます。
ラウンドごとに異なるキーを使用してみましたが、変更はありません。表示されたもの以外は、TempData をチェックしていないので、何らかの方法で値が削除対象としてマークされることはありません。また、[AllowAnonymous] 属性があるかどうかに関係なく、Payment メソッドで失敗します (http から https への切り替えなどによるものではありません。
それは非常に単純なものに違いないように思えますが、私の検索では何も見つかりませんでした。どんな助けでも大歓迎です。
更新:さらに調査すると、何らかの理由で、私のコンテキスト全体がこのステップでホースされているようです。コントローラーで IoC を使用していますが、IoC でインスタンス化された項目はありません。謎が深まる。