C# ASP.net总是要求加载时登录
我正在使用ASP.net和C#,我有一个带有母版页的表单,每次有人进入页面时,我都需要显示登录,当表单中的信息保存在数据库中时,我需要注销 要保存,我使用此代码C# ASP.net总是要求加载时登录,c#,asp.net,C#,Asp.net,我正在使用ASP.net和C#,我有一个带有母版页的表单,每次有人进入页面时,我都需要显示登录,当表单中的信息保存在数据库中时,我需要注销 要保存,我使用此代码 <asp:Button ID="botonAcepto" Text="Guardar" runat="server" ValidationGroup="valida
<asp:Button ID="botonAcepto"
Text="Guardar"
runat="server"
ValidationGroup="validaARCO"
OnClick="btnUpload_Click" />
但是,当我试图强制登录页面时,按钮不起作用。
我尝试了这3种方法来强制加载登录。这些页面加载不同时在同一文档中,它们是我在Default.aspx.cs上尝试的3个设置,用于强制加载时登录
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
HttpCookie cookie1 = new HttpCookie(FormsAuthentication.FormsCookieName, "");
cookie1.Expires = DateTime.Now.AddYears(-1);
Response.Cookies.Add(cookie1);
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
FormsAuthentication.SignOut();
Response.Cookies[FormsAuthentication.FormsCookieName].Expires = DateTime.Now.AddYears(-1);
HttpContext.Current.User = new GenericPrincipal(new GenericIdentity(string.Empty), null);
MaxUsersManager.RemoveSessionCacheItem(Context);
Session.Clear();
Session.Abandon();
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
FormsAuthentication.SignOut();
FormsAuthentication.RedirectToLoginPage();
}
}
这3个示例使按钮变得无用,表单转到登录页面而不保存数据
我怎样才能解决这个问题?是否有其他方法可以始终强制用户登录以输入表单,并在保存数据时注销?
谢谢。这些页面是从logout.aspx页面加载的?@kblok不,页面是从我的主页加载的。为什么不在按钮单击中对注销进行编码?@kblok它在那里,但是如果用户以前是从网站的其他部分登录的,它不会要求登录。
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
HttpCookie cookie1 = new HttpCookie(FormsAuthentication.FormsCookieName, "");
cookie1.Expires = DateTime.Now.AddYears(-1);
Response.Cookies.Add(cookie1);
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
FormsAuthentication.SignOut();
Response.Cookies[FormsAuthentication.FormsCookieName].Expires = DateTime.Now.AddYears(-1);
HttpContext.Current.User = new GenericPrincipal(new GenericIdentity(string.Empty), null);
MaxUsersManager.RemoveSessionCacheItem(Context);
Session.Clear();
Session.Abandon();
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
FormsAuthentication.SignOut();
FormsAuthentication.RedirectToLoginPage();
}
}