三层基于角色的认证 [英] role based authentication in three tier

查看:72
本文介绍了三层基于角色的认证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建一个app_code

在其中创建两个文件夹,第一个文件夹命名为业务逻辑层,第二个文件夹命名为数据逻辑层

在每个文件夹中创建一个类

在业务逻辑层下

create an app_code

create two folders in it first folder named as business logic layer and second as data logic layer

create a class in each folders

under business logic layer

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
public class database
{
    public database()
    {
    }
    public int Load_Redirect()
    {
        businesslogic obj = new businesslogic();
        try
        {
            switch ((int)obj.Load().Rows[0][0])
            {
                case 1:
                    return 1;
                case 2:
                    return 2;
                case 3:
                    return 3;
                default:
                    return 0;
            }
        }
        catch (IndexOutOfRangeException ex)
        {
            return 0;
        }
        finally
        {
            obj = null;
        }
    }
}


在数据逻辑层下


under data logic layer

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI.WebControls;
using System.Web.UI;
public class businesslogic
{
    SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=test;Integrated Security=True");
    public businesslogic()
    {
        con.Open();
    }
    public DataTable Load()
    {
        Page page = (Page)HttpContext.Current.Handler;
        TextBox tb1 = (TextBox)page.FindControl("TextBox1");
        TextBox tb2 = (TextBox)page.FindControl("TextBox2");
        string sql = string.Format("select r.rid from employee e  inner join specification1 r on r.eid =e.eid where uname='" + tb1.Text + "' and password='" + tb2.Text + "'");
        DataSet ds = new DataSet();
        SqlDataAdapter da = new SqlDataAdapter(sql,con);
        try
        {
            da.Fill(ds, "d");
            return ds.Tables["d"];
        }
        catch (SqlException ex)
        {
            throw;
        }
        finally
        {
            ds.Dispose();
            da.Dispose();
            con.Close();
            con.Dispose();
        }
    }
}


在您的默认页面中


in ur default page

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="Label1" runat="server" Text="uname"></asp:Label>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Label ID="Label2" runat="server" Text="pass"></asp:Label>
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="submit" onclick="Button1_Click" />
        <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
    </div>
    </form>
</body>
</html>


c#


c#

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.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        database obj = new database();
        if((int)obj.Load_Redirect()==1)
            Response.Redirect("admin.aspx");
        else if((int)obj.Load_Redirect()==2)
            Response.Redirect("super.aspx");
        else if ((int)obj.Load_Redirect()==3)
            Response.Redirect("user.aspx");
        else
            Label3.Text="missmatch";
    }
}

推荐答案

您必须从商务逻辑中提取aspx文本框,并将其传递给参数.您是否尝试过使用mvc并阅读有关它的书?您会发现非常有趣的隔离概念,以及如何在更少的维护时间下更好地组织代码.

又是什么问题?
You have to extract the aspx textboxes out of the buisiness logic and pass it through parameters. Have you tried to use mvc and read a book about it? You will find very intresting the consept of isolation and how you can organise your code better for less maintanance time.

what was the question again?


这篇关于三层基于角色的认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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