[英]Login form [RedirectFromLoginPage] not working, Master Pages
I am working over a login page in asp.net c# however once I wrote my code it simply does nothing at all. 我正在asp.net c#中的登录页面上工作,但是一旦编写了代码,它根本就什么也不做。 I am using a RedirectFromLoginPage but it seems something is wrong with the code and/or the .net version which I am not 100% sure. 我正在使用RedirectFromLoginPage,但是代码和/或.net版本似乎出了点问题,我不确定100%。
This is my code: 这是我的代码:
protected void LoginForm_Authenticate(object sender, AuthenticateEventArgs e)
{
try
{
System.Threading.Thread.Sleep(1000);
using (var context = new CompanyEntities())
{
//var collection = (from p in context.CP_BlockedAccounts where p.Email == LoginForm.UserName select p);
ValidateIfCustomerIsBlocked Validator = new ValidateIfCustomerIsBlocked();
if (Validator.Validate(LoginForm.UserName) == true)
{
// Account Blocked
// Blocked_Alert.Visible = true;
// Blocked_Alert_Label.Text = "¡Lo sentimos!, al parecer su cuenta se encuentra bloqueada temporalmente, por favor comuniquese con nosotros lo antes posible para resolver su problema.";
}
else
{
var query = (from p in context.CP_Register where p.Email == LoginForm.UserName && p.Password == LoginForm.Password select p);
foreach (var item in query)
{
FormsAuthentication.RedirectFromLoginPage(item.Email, false);
API.CompanyId.CompanyIdentity = item.Id;// Id of the company, global variable
}
}
}
}
catch (Exception ex)
{
LoginForm.FailureText = ex.ToString();
}
}
Once this page loads, it redirects to the dashboard page, which is linked with a master page, this is my code on master page: 加载该页面后,它将重定向到与母版页链接的仪表板页面,这是我在母版页上的代码:
protected void Page_Init(object sender, EventArgs e)
{
if (!this.Page.User.Identity.IsAuthenticated)
{
FormsAuthentication.RedirectToLoginPage();
Session.RemoveAll();
Session.Abandon();
FormsAuthentication.SignOut();
}
else
{
if (CompanyId == 0)
{
Session.RemoveAll();
Session.Abandon();
FormsAuthentication.SignOut();
Response.Redirect("~/Login");
}
else
{
//this.Bind_Header();
//string ImageURL = "~/API/Handlers/Image.ashx?User=" + CompanyId.ToString();
//DropDownImage.ImageUrl = ImageURL;
//MainImage.ImageUrl = ImageURL;
//ImageSideBar.ImageUrl = ImageURL;
}
}
}
The information which I am using is correct such as the password and the email/username however once it gets to the master page it says the user is not authenticated. 我正在使用的信息是正确的,例如密码和电子邮件/用户名,但是一旦进入母版页,则表明用户未通过身份验证。
Could somebody help me out please with this issue? 有人可以帮我解决这个问题吗?
Thanks in advance. 提前致谢。
The way I just solved the problem is by commenting the following lines of code in the web.config. 我刚刚解决问题的方法是在web.config中注释以下代码行。
<system.webServer>
<modules>
<!--<remove name="FormsAuthentication" />-->
<remove name="ApplicationInsightsWebTracking" />
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
</modules>
<validation validateIntegratedModeConfiguration="false" />
Thanks to all to helped me out. 谢谢大家的帮助。 This normally happens when a new project is created. 创建新项目时通常会发生这种情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.