Web配置中的角色不起作用 [英] role in web config is not working

查看:67
本文介绍了Web配置中的角色不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

有人可以帮我解决这个问题吗.已经一个礼拜了.我不知道该如何解决..
我的登录页面到达人力资源表(oracle),然后我将其(role)与自己的表进行比较.

Hi all,

can someone help me on this problem.it''s been a week.i dont know how to solve this..
my login page is reach to human resource table (oracle) then i compare (role) to my own table..

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim con As New OracleConnection(OracleString)
        con.Open()
        Dim log As String
        log = "Select Distinct J.Emplid, P.Name, " +
        "C.Descr Dept From PS_JOB J, PS_JOB JD " +
        "Where J.Emplid = '" + Request("UID") + "' "
       

        Dim cm As New OracleCommand(log, con)
        cm.Connection = con
        'cm.CommandText = log
        'Dim name As String = DirectCast(cm.ExecuteScalar(1), String)
        'Label1.Text = DirectCast(cm.ExecuteScalar(1), String)
        'cm.ExecuteNonQuery()
        Dim d As OracleDataReader = cm.ExecuteReader()
        d.Read()
        Label1.Text = d.GetString(1)
        Label4.Text = d.GetString(3)

        Session("sEmplid") = d.GetString(0)
        'Dim cm As New OracleCommand()
        'cm.Connection = con
        'cm.CommandText = log
        'Dim id As String = DirectCast(cm.ExecuteScalar(0), String)
        'Label3.Text = DirectCast(cm.ExecuteScalar(0), String)
        Session("sNama") = Label1.Text
        Session("sDept") = Label4.Text
        'Session("sEmplid") = Label3.Text

       
        checkrole()



    End Sub

    Protected Sub checkrole()
        Dim role As String
        Dim con As New SqlConnection(connectionString)
        con.Open()
        If (Session("sEmplid") <> "") Then
            Dim r As String = "Select roles from logs where Emplid = '" + Session("sEmplid") + "'"
            Dim c As New SqlCommand(r, con)
            c.Connection = con
            Dim d As SqlDataReader = c.ExecuteReader()
            d.Read()
            If DBNull.Value.Equals(d("roles")) Then
                Label2.Text = "user"
                role = Label2.Text
                Session("sRole") = role
                Response.Redirect("home.aspx")
            Else
                Label2.Text = d.GetString(0)
                role = Label2.Text
                Session("sRole") = role
                Response.Redirect("home.aspx")
            End If
        Else
            Response.Redirect("login.aspx")

        End If


        If (Session("sRole") = "user" Or Session("sRole") = "manager" Or Session("sRole") = "general" Or Session("sRole") = "master") Then
        
        Response.Redirect("home.aspx")
        Else
        Response.Redirect("login.aspx")
        End If

       
    End Sub


web.config:


web.config:

<sitemap enabled="true">
            <providers>
                <clear />
                <add sitemapfile="Web.sitemap" name="AspNetXmlSiteMapProvider" type="System.Web.XmlSiteMapProvider" securitytrimmingenabled="true" />
            </providers>
        </sitemap>

        <authentication mode="Forms">
            <forms name ="pageForm" loginUrl="~\login.aspx" defaultUrl="~\home.aspx"></forms>
        </authentication>




    <location path="approval.aspx">
            <system.web>
                <authorization>
                    <allow users="master" />
                    <deny users="*" />
                </authorization>
            </system.web>
        </location>


web.sitemap:


web.sitemap:

<sitemap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0">
    <sitemapnode roles="*">
        <sitemapnode url="home.aspx" title="Home" description="" />
        <sitemapnode url="status.aspx" title="Status" description="" />
        <sitemapnode title="Approval by GM ISM" description="GM ISM Use Only" url="approval.aspx" />
        <sitemapnode url="logout.aspx" title="Logout" description="" />
    </sitemapnode>


</sitemap>






问题是;每当我登录时(无论使用哪个用户ID),都会为角色用户显示菜单.似乎角色大师在Web配置中根本不起作用..请帮助我..

谢谢
musiw.






the problem is; whenever i login (no matter what user id) the menu appear for role user. seems like role master doesnt work at all in web config..please help me..

thanks
musiw.

推荐答案

从简短地查看已完成的工作,您似乎忘记了在设置会话变量和角色后使用FormsAuthentication.SetAuthCookie对用户进行身份验证.

这是指向有关使用SQL Server进行表单身份验证的CP文章的链接,但是您应该能够用Oracle代码替换SQL部分.

FormsAuthentication.SetAuthCookie(用户名,false); [ ^ ]

祝你好运!
From briefly looking over what you have done, it looks like you forgot to authenticate the user using FormsAuthentication.SetAuthCookie after you set the session variables and roles.

Here is a link to a CP article on forms authentication with SQL Server, but you should be able to replace the SQL part with your Oracle code.

FormsAuthentication.SetAuthCookie(username, false);[^]

Best of luck!


这篇关于Web配置中的角色不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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