我只想在 asp.net 3.5 中会话过期时将用户重定向到主页(Default.aspx)。
我只是用网络用户控制来做到这一点,但钢它不能完美地工作。所以我只想用 web.config 来做到这一点。
<authentication mode="Forms">
<forms loginUrl="~/SignIn.aspx" protection="All" timeout="2880" path="/" />
</authentication>
该技术适用于 .net 3.5 框架应用程序吗?
对于无母版页:
你可以试试这个。
protected void Page_Load(object sender, EventArgs e)
{
if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
{
if (!IsPostBack)
{
}
}
else
{
Response.Redirect("Default.aspx", false);
}
}
在每个网页中使用这个逻辑
如果使用母版页:
在 masterpage.cs 文件中使用上述逻辑
使用Web.Config:
<authentication mode="Forms">
<forms loginUrl="~/SignIn.aspx" protection="All" timeout="2880" path="/" />
</authentication>
<authorization>
<deny users="?" />
</authorization>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)