如果会话变量为空,则限制页面访问 [英] Restrict Page access if session variable is empty

查看:108
本文介绍了如果会话变量为空,则限制页面访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Asp.net开发一个小应用程序。我已经创建了一个管理面板。某些页面仅可供管理员登录访问。如果未设置admin loggin会话变量,我想限制对这些页面的访问。在检查是否设置了SESSION变量时,即使设置了会话变量,它仍会在登录页面上重定向,请通过我的代码

I am developing a small application in Asp.net . I have created an admin panel in that. Certain Pages are accessible to admin login only . I want to restrict access to those pages if admin loggin session variable is not set. On checking whether the SESSION variable is set , it still redirects me on the login page even if the session variable is set, please go through my code

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        if (Convert.ToString(Session["loggeduername"])=="")
        {
           Response.Redirect("adminlogin.aspx");
        }



    }
}

推荐答案

这样做。

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



检查设置值的页面, ds.Tables [0] .Rows [0] .ItemArray [1] .ToString()包含值。

问候......:笑:


Check at the page where you set the value that,ds.Tables[0].Rows[0].ItemArray[1].ToString() contains value.
Regards..:laugh:


这篇关于如果会话变量为空,则限制页面访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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