[英]Redirecting to specific page after Login
I have three pages in my application. 我的申请表中有三页。
Login.aspx 为Login.aspx
Report.aspx Report.aspx
Main.aspx Main.aspx
When users click on the www.abc123.com/Report.aspx url if they are not signed in I am directing them to www.abc123.com/Login.aspx page but after they login I want to show Report.aspx page instead of Main.aspx page. 当用户点击www.abc123.com/Report.aspx网址时,如果他们没有登录,我会将他们导向www.abc123.com/Login.aspx页面,但在他们登录后我想显示Report.aspx页面而不是Main.aspx页面。 Below id my code: 下面是我的代码:
protected String Username
{
get
{
return Convert.ToString(Session["LoggedInUser"]);
}
}
protected void Page_Load(object sender, EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Today.AddDays(-1));
Response.Cache.SetNoStore();
if (String.IsNullOrEmpty(Username))
{
Response.Redirect("Login.aspx");
}
there are numerous articles on the net. 网上有很多文章。 here is a simple one - http://support.microsoft.com/kb/301240 这是一个简单的 - http://support.microsoft.com/kb/301240
As I understand your question and problem context, I suspect that you have a project that contains both the remainders of out-of-the-box forms based authentication and also some custom authentication code. 正如我理解您的问题和问题上下文,我怀疑您有一个项目既包含基于开箱即用表单的身份验证的剩余部分,也包含一些自定义身份验证代码。
The short way to solve your problem would be to configure the page that the login page redirects to in web.config by setting the defaultPage-attribute of the forms -element. 解决问题的简短方法是通过设置forms -element的defaultPage-attribute来配置登录页面在web.config中重定向到的页面。
But as this question is related to security, I strongly suggest to learn about the mechanisms of ASP.NET forms based authentication . 但由于这个问题与安全性有关,我强烈建议您了解基于ASP.NET表单的身份验证的机制。 A clean approach involves: 一个干净的方法涉及:
This would also build a good base if you need to add other pages that are restricted for a certain audience. 如果您需要添加受特定受众限制的其他页面,这也将构建一个良好的基础。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.