ユーザーが [サインイン] ボタンを押すと、コントローラーの次の関数が実行され、ユーザーの名前を次のように設定しますSetAuthCookie
。
// POST: /Account/SignUp
[HttpPost]
public ActionResult Index(ConsumerView consumerData)
{
try
{
ConsumerManager consumerManagerObj = new ConsumerManager();
if (consumerManagerObj.IsValidUser(consumerData.LoginID, consumerData.Password))
{
FormsAuthentication.SetAuthCookie(consumerData.FirstName, false);
return View ("WelcomeConsumer");
}
else
{
ModelState.AddModelError("", "Invalid Username/Password!!");
}
}
catch
{
return View(consumerData);
}
return View(consumerData);
}
WelcomeConsumer
ビューにはコードがあります:
@{
ViewBag.Title = "Home";
}
<h2>Welcome</h2>
<h2>Hi <b>@Context.User.Identity.Name</b></h2>
@Html.ActionLink("[Sign Out]", "SignOut", "ConsumerAccount")
<p>
<ul>
<li>@Html.ActionLink("Book new Ticket", "NewBooking", "ConsumerAccount")</li>
<li>@Html.ActionLink("View all Bookings", "ViewAllBookings", "ConsumerAccount") </li>
</ul>
@ViewBag.NewBookingSuccess
</p>
ただし、@Context.User.Identity.Name
常に空の値を入れてください。解決策はありますか?