I'm working with a custom asp.net membership provider in conjunction with the default Account controller that comes with the asp.net MVC example app. Everything is going smoothly except for one tiny thing: After a user creates an account and is automatically logged in and redirected, their username is not displayed with the usual welcome message.
I thought perhaps this was because they were not logged in at the time they made the request. Once they log in again their name appears at the top, so I don't think it's the membership providers fault, but I could be wrong.
The register and redirect controller method that ships with asp.net MVC looks like this:
public ActionResult Register(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("Index", "Home");
}
else
{
ModelState.AddModelError("_FORM", ErrorCodeToString(createStatus));
}
}
// If we got this far, something failed, redisplay form
return View();
}
This is using forms authentication by the way.
Edit: Here is the Master page used by the Index page. It's the Site.master that ships with the default asp.net MVC application:
<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
<div id="header">
<div id="title">
<h1>Internship Site</h1>
</div>
<div id="logindisplay">
<% Html.RenderPartial("LogOnUserControl"); %>
</div>
<div id="menucontainer">
<ul id="menu">
<li><%= Html.ActionLink("Home", "Index", "Home")%></li>
<li><%= Html.ActionLink("About", "About", "Home")%></li>
</ul>
</div>
</div>
<div id="main">
<noscript>Your browser does not support JavaScript!</noscript>
<asp:ContentPlaceHolder ID="MainContent" runat="server" />
<div id="footer">
</div>
</div>
</div>
Any help and insight greatly appreciated.