c# - How to actually logout from a website rather than simply redirecting to login page? -
i using response.redirect facility send user login page when clicks logout image button not perform logout operation , when user clicks backspace button in keyboard or button in browser user screen gets displayed back. how control situation in c# asp.net , have read posts saying session should cleared before redirecting dont know how apply in form. have enclosed coding below , request me out of situation in clear manner.
in loginpage.aspx
protected void btnlogin_click1(object sender, eventargs e) { var query = (from row in db.logins row.userid == txtuname.text && row.password == txtpassword.text select new { row.userid, row.password, row.admin_roll, row.manager_roll}).distinct(); if (query.count() > 0) { if (query.single().admin_roll == 1) { response.redirect("~/homepage.aspx"); } else if (query.single().manager_roll == 1) { response.redirect("~/detailspage.aspx"); }
and in masperpage.master
protected void imagebutton1_click(object sender, imageclickeventargs e) { response.redirect("~/loginpage.aspx"); }
suggest me solution.
for have clear
session , cookies browser using c# code.
- logoutpage.aspx
`
protected void page_load(object sender, eventargs e) { response.cache.setcacheability(httpcacheability.nocache); response.cache.setexpires(datetime.utcnow.addhours(-1)); response.cache.setnostore(); session.abandon(); session.clear(); system.web.security.formsauthentication.signout(); // not redirect login page here // redirect login page javascript }
`
and same way have clear browser
history
using javascript on page load
`
<script type="text/javascript"> $(document).ready(function () { var url = window.location.href; window.history.go(-window.history.length); window.location.href = 'login.aspx'; // redirect login page }); </script>
`
updated answer: better make different page logout logout.aspx
, write code in page_load
event of logout.aspx
page. , write above javascript in <head>
tag in logout.aspx
page.
Comments
Post a Comment