使用用户类型在ASP.NET中登录页面 [英] Log In Page in ASP.NET with User Type

查看:80
本文介绍了使用用户类型在ASP.NET中登录页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

首先..我有一个数据库...

dbName:数据库
tblName:tblUser
字段名称:UserID,UserPassword,UserType

例如:

alc14647、12345,管理员
bti12345,67890,用户
ggt09876、45673,编辑器
等等等等

我的问题是...我如何启用或隐藏ex.[按钮或标签]
用户类型是否已登录?

我有一个单独的登录页面,一个我的布局的主页面,另一个页面被选为内容的主页面

前任.管理员可以查看或启用某些按钮或标签
并且用户登录后只能使用或看到特定的标签或按钮,

我的按钮或标签是

LABEL1
LABEL2
LABEL3
LABEL4
LABEL5
LABEL6
LABEL7
LABEL8
LABEL9

所有标签都可以在MASTER PAGE注释中看到ADMIN [该标签不是ContentPageHolder,我将其放在外面]
并且其他用户可以看到在其SPECIFIC类型上的标签,

这是我的单独登录"页面的代码,它也位于同一项目中[希望您会得到它^ _ ^]

HELLO EVERYONE

first.. i have a database...

dbName: Database
tblName: tblUser
FieldNames: UserID, UserPassword, UserType

example:

alc14647, 12345, admin
bti12345, 67890, user
ggt09876, 45673, editor
blah blah blah

my question is... how do i enabled or hide ex.[buttons or lables]
if the user type is logged in?

i have a SEPARATE LOG IN PAGE, and a MASTER PAGE for my layout and the other page is selected MASTER PAGE for the CONTENTS

ex. admin can see or enable to use a certain buttons or lables
and the user can only use or see a specific labels or buttons after log in,

my buttons or labels are

LABEL1
LABEL2
LABEL3
LABEL4
LABEL5
LABEL6
LABEL7
LABEL8
LABEL9

all the labels can see the ADMIN in the MASTER PAGE note[that labels is isn''t the ContentPageHolder, i put it in the OUTSIDE]
and the other user can SEE that labels on their SPECIFIC type,

this my CODE for my SEPARATED Log in page and it''s in the same project located also[hope you''v gonna get it^_^]

Imports System.Data.OleDb

Partial Class _Default
    Inherits System.Web.UI.Page
    Dim cn As New OleDbConnection
    Dim cmd As New OleDbCommand
    Dim dr As OleDbDataReader

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        txtUsername.Focus()
        Label1.Text = ""
        Try
            With cn
                If .State = Data.ConnectionState.Open Then .Close()
                .ConnectionString = "Provider=microsoft.jet.oledb.4.0;data source=" &; Server.MapPath("data\database.mdb")
                .Open()
            End With
        Catch ex As Exception
            MsgBox(ex.Message.ToString)
        End Try
    End Sub

Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogin.Click
        If txtUsername.Text = "" Or txtPassword.Text = "" Then Exit Sub
        With cmd
            .CommandText = "Select * from tbluser Where userid = ''" & Trim(txtUsername.Text) & "'' and passid = ''" Trim(txtPassword.Text) &"'' "
            .Connection = cn
            dr = .ExecuteReader
        End With

        If dr.HasRows Then
            Session("name") = txtUsername.Text ''it will display o the other page, it depends
            Response.Redirect("Main.aspx") ''my main.aspx is connected to my MASTER PAGE and all the other page
        Else
            Label1.Text = ("ERROR! " & txtUsername.Text)
        End If
    End Sub
End Class


我要做什么代码?还有我要放在哪里?

请..我需要一些帮助...
仅启用,禁用,可见= TRUE或FALSE取决于用户类型的特定项目(如按钮和标签)...

感谢您的阅读,我希望读者可以帮助我..
感谢ADVANCE ^ _ ^


what code i''m gonna suppose to do? and where i''m gonna put it??

please.. i need some help...
just to enabled, disabled, visible = TRUE or FALSE the specific ITEM like BUTTONS and LABELS that depends on the USERTYPE...

thank for READING i hope READER''s can HELP ME..
THANKS in ADVANCE ^_^

推荐答案

我将使用PlaceHolder对象,使始终显示最低安全性的对象,然后基于以下对象使较高安全性的对象可见用户的角色.当然,这简化了整个过程,但是我想您已经明白了.
I would use PlaceHolder objects, making the lowest-security one always visible, and then making the higher security ones visible based on the user''s role. Of course, this is over simplifying the whole thing, but I think you get the picture.


这篇关于使用用户类型在ASP.NET中登录页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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