c# - 登录表单 [RedirectFromLoginPage] 不起作用,母版页
问题描述
我正在处理 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;
}
}
}
我使用的信息是正确的,例如密码和电子邮件/用户名,但是一旦它进入母版页,它就会说用户没有经过身份验证。
有人可以帮我解决这个问题吗?
提前致谢。
解决方案
我刚刚解决问题的方法是在 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" />
感谢所有帮助我的人。 这通常发生在创建新项目时。
推荐阅读
- mysql - 将大型 sql 文件(每天 30 gb)导入到 elasticseach 中的单个索引
- bash - Bash:如何检查目录是否存在以及其中是否包含文件
- amazon-web-services - 使用 ansible shell 模块时如何使 aws 命令对 sh 可用?
- c# - 代码返回 true 但数据不在表中
- javascript - IntersectionObserver:找出元素何时在视口之外
- javascript - 带有参数的Rails远程表单
- flutter - 用于 Web 状态管理的 Flutter
- php - 在 sendinblue 中发送请求 curl php 时出错
- r - R:如何根据索引向量从每一行中选择一个值?
- ios - 在 PageViewController 中获取 ViewController 的 containerView