使用母版页和 Windows 身份验证的 asp.net c# 中的注销或注销问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1037620/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Logout or signout problem in asp.net c# using Master page and windows authentication
提问by
I am new in asp.net, My problem is facing logout problem in myappication using master page and window authentication. After i signout from my application if i use browser back button it again goes back to signed page after that i click any control then only it is goes back to the logout stage but i want to dont show the logged page unnessarily.
我是 asp.net 的新手,我的问题是在使用母版页和窗口身份验证的 myappication 中面临注销问题。在我退出我的应用程序后,如果我使用浏览器后退按钮,它会再次返回到签名页面,然后我单击任何控件然后它才返回到注销阶段,但我不想不正常地显示已记录的页面。
i am using href,document.location.replace(page),response.write("mypage.aspx") these technique for naviagation purpose and i am using session in all pages.
我正在使用 href,document.location.replace(page),response.write("mypage.aspx") 这些技术用于导航目的,并且我在所有页面中都使用会话。
Note: I am using login and logout in master page top itself...so if i check the session for null redirect to home page which is also a content page then i am not getting the home page it self to login because infinite looping occurs...
注意:我在母版页顶部使用登录和注销...所以如果我检查会话是否为空重定向到主页,这也是一个内容页面,那么我不会让主页自己登录,因为会发生无限循环...
when i am searching i got some coding to clear the cache but i a am facing problem that is after i logged and navigate to some of pages then i click browser backbutton without signout it is showing page is expired Click refresh to get the data back....
当我搜索时,我得到了一些代码来清除缓存,但我面临的问题是在我登录并导航到某些页面之后,然后我单击浏览器后退按钮而不注销它显示页面已过期单击刷新以获取数据。 ..
Finally, I need solution like google signout i.e: after signout from google page then if we use back it shows only the home page. and please tell which event is fired while clicking the browser backbutton if yes how to validate session and redirect to logout page.
最后,我需要像谷歌注销这样的解决方案,即:从谷歌页面注销后,如果我们使用 back 它只显示主页。并且请告诉在单击浏览器后退按钮时触发哪个事件(如果是)如何验证会话并重定向到注销页面。
Please help me i am facing these problem in one-week....
请帮助我,我在一周内面临这些问题....
Thanks in advance to everyone..
提前感谢大家..
回答by StuperUser
You could consider in the Masterpage Page_Load
to check for login credentials (however they are implemented in your solution) and if they are not present, to Response.Redirect()
to the login or home page.
您可以考虑在 MasterpagePage_Load
中检查登录凭据(但它们是在您的解决方案中实现的),如果它们不存在,Response.Redirect()
则检查登录或主页。
Edit: I'm not sure whether the OnLoad event is raised when using the back button. This approach may not work.
编辑:我不确定使用后退按钮时是否引发 OnLoad 事件。这种方法可能行不通。
回答by James
回答by Jalindar
Login Page
登录页面
protected void Page_Load(object sender, EventArgs e)
{
Session["imp"] = "0";
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
Session["imp"] = "1";
Response.Redirect("AdminHome.aspx");
}
Log Out Page
登出页面
protected void Page_Load(object sender, EventArgs e)
{
Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
if (Session["imp"].ToString() == "1")
{ }
else
{
Response.Redirect("HomePage.aspx");
}
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
Session["imp"] = "0";
Session.Abandon();
Response.Clear();
Response.Redirect("HomePage.aspx");
}