我正在asp.net c#中的登录页面上工作,但是一旦我编写了代码,它根本就什么也不做。我使用的是RedirectFromLoginPage,但似乎代码和/或.net版本出了点问题,但我不确定100%。
这是我的代码:
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();
}
}
此页面加载后,将重定向到与母版页链接的仪表板页,这是我在母版页上的代码:
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;
}
}
}
我正在使用的信息是正确的,例如密码和电子邮件/用户名,但是一旦进入母版页,则表明用户未通过身份验证。
有人可以帮我解决这个问题吗?
谢谢。
答案 0 :(得分:0)
我刚解决问题的方法是在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" />
感谢所有人的帮助。 通常在创建新项目时发生。