检测形式的登录页面认证超时 [英] Detecting forms authentication timeout in login page
问题描述
当你有窗体身份验证设置重定向访问受保护的页面时login.aspx的,什么是在login.aspx的检测的好办法该用户是否被送到那里,因为他们还没有登录上还没有,或者因为它们的形式身份验证票证已过期?我想显示你已经超时消息。
When you have forms authentication setup to redirect to login.aspx when accessing a protected page, what's a good way to detect in login.aspx whether the user was sent there because they haven't logged on yet, or because their forms auth ticket is expired? I'd like to display a "you've timed out" message.
(我不提这个问题的话会话,因为ASP.NET把他们如此明显,但是,如果有涉及会话很好的解决,我洗耳恭听)
(I do not mention the word session in this question, because ASP.NET treats them so distinctly, however, if there is a good solution that involves session, I'm all ears)
我已经通过具有另一库克hasloggedin设置当用户登录,然后检查是否存在以确定它是否是一个超时,然后显示相应的消息,在过去解决了这个。但是,这已经是一个普遍的问题?
I've solved this in the past by having another cooke "hasloggedin" set when a user logs in and then checks to see if that exists to determine if it's a timeout and then display an appropriate message. But, this has to be a common problem?
推荐答案
Forms身份验证会自动追加一个URL参数RETURNURL',指明哪个页面(如果有的话)触发重定向到登录页面。大多数网站有一个'Default.aspx的'或'的index.html'等作为默认的页面。您可以检查RETURNURL,看它是否包含默认页面,或者在应用程序中其他网页。
Forms authentication will automatically append a URL parameter 'ReturnURL', indicating what page (if any) triggered the redirection to the login page. Most websites have a 'Default.aspx' or 'index.html' etc as the default page. You can check the ReturnURL to see if it contains the default page, or some other page in your application.
例如:
string refererURL;
if (page.Request.QueryString["ReturnURL"] != null)
{
refererURL = page.Request.QueryString["ReturnURL"].ToString();
}
//Check to see if user was redirected because of Timeout or initial login
//Where "Default.aspx" is the default page for your application
if (refererURL != "" && refererURL != (ResolveUrl("~") + "Default.aspx"))
{
//Show HTML etc showing session timeout message
}
else // User redirected here to to initial login
{
//Show HTML showing initial login HTML message etc
}
这篇关于检测形式的登录页面认证超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!