登录以访问和注销.然后在我输入url之后将显示page.idont想要这样 [英] login to access and logout.then after i enter url it ll be display page.idont want like that

查看:68
本文介绍了登录以访问和注销.然后在我输入url之后将显示page.idont想要这样的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 好友

我在该应用程序中只有一个应用程序,我使用用户名和密码登录,然后注销后访问应用程序中的所有页面.

这是主要的事情

我注销,然后在键入url之后,例如http://localhost:2424/sample/select.aspx
将会显示.

我需要在那个时候显示登录页面(我在url上方键入的任何页面我都想显示登录页面).


而且在我注销后,我也不想使用前进和后退按钮.

如果我注销,则单击后退"或前进"按钮后,我需要显示登录页面.

谢谢与问候
Venkat.S

Hi Friends

i have one application in that application i login using username and password then i access all pages in my aplication then after i logout.

this is main thing

i logout then after i type url like http://localhost:2424/sample/select.aspx
it ll be display.

i need to display login page in that time(any page i type above url i want to display login page).


and also after i logout i dont want to work back and forward button.

if i logout then after i click back or forward button i need to display login page.

Thanks&Regards
Venkat.S

推荐答案

要注销后退按钮,请查看:
For logout back button issue, look: Browser back button issue after logout[^]


For having a login button on URL navigation after logout:
At login, when user is authenticated:
Session["IsLoggedIn"] = "Yes";
//OR
Session["LoggedInUserId"] = "User621";



注销时,清除会话:



At the time of logout, clear the session:

Session.Clear();
//OR 
Session["IsLoggedIn"] = null;



如果要检查用户是否登录,只需查看会话值是否存在.如果它为null,则它们未通过身份验证,因此将其定向到登录URL.



If you want to check if user is logged in or not, just see if session value exists. If it''s null then they are not authenticated and so direct them to Login URL.


在每个页面加载时,只需检查Session的值,如果为null,则只需返回即可到登录页面.

On every page load just check the value of the Session, if this is null then simply just return to the login page.

protected void Page_Load(object sender, EventArgs e)
{
    if (Session["UserID"] == null)
        Response.Redirect("loginPage.aspx");
}


但更好的方法是创建另一个页面,例如BasePage并使用"System.Web.UI.Page"继承它,每个.aspx.cs应该与此BasePage继承.

现在,您只能在BasePage中纠正一次此逻辑.


but better approach is create another page e.g. BasePage and inherit it with "System.Web.UI.Page" and each .aspx.cs should inherit with this BasePage.

Now u can right this logic only once in the BasePage.

public class basePage : System.Web.UI.Page
    {
        protected override void OnLoad(EventArgs e)
        {
            if (Session["UserID"] == null)
                Response.Redirect("loginPage.aspx");
            base.OnLoad(e);
        }
    }





public partial class _Default : basePage


这篇关于登录以访问和注销.然后在我输入url之后将显示page.idont想要这样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆