需要有关页面安全性的信息 [英] need information about page security

查看:74
本文介绍了需要有关页面安全性的信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



我正在开发一个基于网络的应用程序。

第一页登录

所以,如果登录确定,那么它将转到欢迎页面



现在每个页面都有它自己的网址



i want是假设我复制了第二个表单的url并将其复制到浏览器然后它不应该在没有身份验证的情况下打开..意思是它应该自动重定向到登录页面



请告诉我怎么做

Hi all

I am developing one web based application.
the first page is login
so if login is ok then it will go to welcome page

now each page is having it''s own url

i want is suppose i copied the url of second form and copy it to the browser then it should not open without authentication..means it should redirect to the login page automatically

Please tell me how to do this

推荐答案

为此用途ASP.NET会话状态 [ ^ ] ...



每当用户登录时,在Session中存储用户名,并且

在每个页面的Load事件中,添加此代码..

For that use ASP.NET Session State [^]...

Whenever user get logged in, store username in Session, and
On every page''s Load event, add this code..
if(Session.Count != 0)
{
   Respone.Redirect("Login.aspx");
}
else
{
   return;
}



************************ ***********************************

登录页面:


***********************************************************
Login Page :

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Data.OleDb;

namespace GuitarChordsTabs
{
    public partial class WebForm3 : System.Web.UI.Page
    {
        static string ConStr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Kunal Rohit\Desktop\GuitarChordsTabs\GuitarChordsTabs\App_Data\Database.accdb";
        OleDbConnection con = new OleDbConnection(ConStr);

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session.Count != 0)
            {
                Response.Redirect("Home.aspx");
            }
        }
        protected void loginbtn_Click(object sender, EventArgs e)
        {
            string username, password;

            username = unametxt.Text;
            password = pswdtxt.Text;

            Session["username"] = username;
            Session["password"] = password;

            string SelStr = "select * from Users where User_Name=''" + unametxt.Text + "'' and Password=''" + pswdtxt.Text + "''";
            OleDbDataAdapter da = new OleDbDataAdapter(SelStr, con);
            DataTable usertable = new DataTable("user");
            da.Fill(usertable);

            foreach (DataRow dr in usertable.Rows)
            {
                if (unametxt.Text == dr["User_Name"].ToString() && pswdtxt.Text == dr["Password"].ToString())
                {
                    username = Session["username"].ToString();
                    password = Session["password"].ToString();

                    Response.Redirect("Home.aspx");
                }
                else
                {
                    Response.Redirect("LogIn.aspx");
                }
            }
        }

        protected void logoutLinkBtn_Click(object sender, EventArgs e)
        {
            if (MultiView1.ActiveViewIndex == -1)
            {
                MultiView1.ActiveViewIndex++;
            }
            else
            {
                MultiView1.ActiveViewIndex = -1;
            }

            string SelStr = "select * from Users";
            OleDbDataAdapter da = new OleDbDataAdapter(SelStr, con);
            DataTable users = new DataTable("users");
            da.Fill(users);

            foreach (DataRow dr in users.Rows)
            {
                if (dr["User_Name"].ToString() == unametxt.Text)
                {
                    securityqnstxtfrgtpswd.Text = dr["Security_Question"].ToString();
                }
            }

        }

        protected void getpswdbtn_Click(object sender, EventArgs e)
        {
            string SelStr = "select * from Users";
            OleDbDataAdapter da = new OleDbDataAdapter(SelStr, con);
            DataTable users = new DataTable("users");
            da.Fill(users);

            foreach (DataRow dr in users.Rows)
            {
                if (dr["Security_Answer"].ToString() == securityanstxtfrgtpswd.Text)
                {
                    System.Windows.Forms.MessageBox.Show("Your Password is " + dr["Password"].ToString(), "Guitar Chords & Leads", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Asterisk);
                }
            }
           
        }
    }
}





任何页面;



Any Page;

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

namespace GuitarChordsTabs
{
    public partial class WebForm8 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session.Count == 0)
            {
                Response.Redirect("LogIn.aspx");
            }
            else
            {
                return;
            }
        }

        protected void LinkButton20_Click(object sender, EventArgs e)
        {
            Session.Clear();
            Response.Redirect("Home.aspx");
        }
    }
}


这篇关于需要有关页面安全性的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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