Using the same basic code that is the default master page when you select a web site project C3, I put the login form in a modal panel and try to oen it from the master. I have done this in VS2012 and it works fine, but in vs2015, clicking the login button does not seem to fire the onClick event. It just sits there?
private const string AntiXsrfTokenKey = "__AntiXsrfToken";
private const string AntiXsrfUserNameKey = "__AntiXsrfUserName";
private string _antiXsrfTokenValue;
public bool IsValid { get; private set; }
protected void Page_Init(object sender, EventArgs e)
{
// The code below helps to protect against XSRF attacks
var requestCookie = Request.Cookies[AntiXsrfTokenKey];
Guid requestCookieGuidValue;
if (requestCookie != null && Guid.TryParse(requestCookie.Value, out requestCookieGuidValue))
{
// Use the Anti-XSRF token from the cookie
_antiXsrfTokenValue = requestCookie.Value;
Page.ViewStateUserKey = _antiXsrfTokenValue;
}
else
{
// Generate a new Anti-XSRF token and save to the cookie
_antiXsrfTokenValue = Guid.NewGuid().ToString("N");
Page.ViewStateUserKey = _antiXsrfTokenValue;
var responseCookie = new HttpCookie(AntiXsrfTokenKey)
{
HttpOnly = true,
Value = _antiXsrfTokenValue
};
if (FormsAuthentication.RequireSSL && Request.IsSecureConnection)
{
responseCookie.Secure = true;
}
Response.Cookies.Set(responseCookie);
}
Page.PreLoad += master_Page_PreLoad;
}
protected void master_Page_PreLoad(object sender, EventArgs e)
{
if (!IsPostBack)
{
// Set Anti-XSRF token
ViewState[AntiXsrfTokenKey] = Page.ViewStateUserKey;
ViewState[AntiXsrfUserNameKey] = Context.User.Identity.Name ?? String.Empty;
}
else
{
// Validate the Anti-XSRF token
if ((string)ViewState[AntiXsrfTokenKey] != _antiXsrfTokenValue
|| (string)ViewState[AntiXsrfUserNameKey] != (Context.User.Identity.Name ?? String.Empty))
{
throw new InvalidOperationException("Validation of Anti-XSRF token failed.");
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Unnamed_LoggingOut(object sender, LoginCancelEventArgs e)
{
Context.GetOwinContext().Authentication.SignOut();
}
protected void LogIn(object sender, EventArgs e)
{
if (IsValid)
{
// Validate the user password
var manager = new UserManager();
ApplicationUser user = manager.Find(UserName.Text, Password.Text);
if (user != null)
{
IdentityHelper.SignIn(manager, user, RememberMe.Checked);
IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
}
else
{
FailureText.Text = "Invalid username or password.";
ErrorMessage.Visible = true;
}
}
} protected void LinkButton1_Click(object sender, EventArgs e)
{
ModalPopupExtender1.Show();
}The bolded line at the bottom is all that I added to the Site. Master page.
<asp:LoginView runat="server" ViewStateMode="Disabled"><AnonymousTemplate><ul class="nav navbar-nav navbar-right"><li><a runat="server" href="~/Account/Register">Register</a></li><li><asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">Sign In</asp:LinkButton></li><%--<li><a runat="server" href="~/Account/Login">Log in</a></li>--%></ul></AnonymousTemplate><LoggedInTemplate><ul class="nav navbar-nav navbar-right"><li><a runat="server" href="~/Account/Manage" title="Manage your account">Hello, <%: Context.User.Identity.GetUserName() %>!</a></li><li><asp:LoginStatus runat="server" LogoutAction="Redirect" LogoutText="Log off" LogoutPageUrl="~/" OnLoggingOut="Unnamed_LoggingOut" /></li></ul></LoggedInTemplate></asp:LoginView></div>
-------------------------------------Modal Popup ----------------------------------------
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" PopupControlID="pnllogin" TargetControlID="btnlogin"></asp:ModalPopupExtender><asp:Button ID="btnlogin" runat="server" Text="Button" style ="display:none;" /><asp:Panel ID="pnllogin" runat="server" style ="display:none;"><div class="col-md-8"><section id="loginForm"><div class="form-horizontal"><h4>Use a local account to log in.</h4><hr /><asp:PlaceHolder runat="server" ID="ErrorMessage" Visible="false"><p class="text-danger"><asp:Literal runat="server" ID="FailureText" /></p></asp:PlaceHolder><div class="form-group"><asp:Label runat="server" AssociatedControlID="UserName" CssClass="col-md-2 control-label">User name</asp:Label><div class="col-md-10"><asp:TextBox runat="server" ID="UserName" CssClass="form-control" /><asp:RequiredFieldValidator runat="server" ControlToValidate="UserName"
CssClass="text-danger" ErrorMessage="The user name field is required." /></div></div><div class="form-group"><asp:Label runat="server" AssociatedControlID="Password" CssClass="col-md-2 control-label">Password</asp:Label><div class="col-md-10"><asp:TextBox runat="server" ID="Password" TextMode="Password" CssClass="form-control" /><asp:RequiredFieldValidator runat="server" ControlToValidate="Password" CssClass="text-danger" ErrorMessage="The password field is required." /></div></div><div class="form-group"><div class="col-md-offset-2 col-md-10"><div class="checkbox"><asp:CheckBox runat="server" ID="RememberMe" /><asp:Label runat="server" AssociatedControlID="RememberMe">Remember me?</asp:Label></div></div></div><div class="form-group"><div class="col-md-offset-2 col-md-10"><asp:Button runat="server" OnClick="LogIn" Text="Log in" CssClass="btn btn-default" /></div></div></div><p><asp:HyperLink runat="server" ID="RegisterHyperLink" ViewStateMode="Disabled">Register</asp:HyperLink>
if you don't have a local account.</p></section></div></asp:Panel>In this version, I can put a debug stop on the LinkButton1_Click event and it never hits it.