Httpcontext.current.user" role"不正常。 [英] Httpcontext.current.user "role" not working properly.

查看:74
本文介绍了Httpcontext.current.user" role"不正常。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





早上好。



我使用基于角色身份验证的站点地图。当传递角色值时,菜单将不会显示。



但是,当我对特定角色进行硬编码时,它将起作用。



工作代码

Hi,

Good Morning.

I used site map with role based authentication. When pass role value the menu will not be displaying.

but, when i hard code the particular role then it will work.

Working code

Dim arr As String() = {"Stu"}
HttpContext.Current.User = New GenericPrincipal(HttpContext.Current.User.Identity, arr)



菜单看起来很完美。



无效代码


menu will be appearing perfect.

Not working code

Dim arr As String() = {Session("Stu")}
HttpContext.Current.User = New GenericPrincipal(HttpContext.Current.User.Identity, arr)



会话值将通过但是,菜单不会出现。



以下是我的代码




Session value will be passing but, menu will not appear.

below is my code

<location path="Administrator">
<system.web>
<authorization>
<allow roles="Adm"/>
<deny users="*" />
</authorization>
</system.web>
</location>
<location path="Student">
<system.web>
<authorization>
<allow roles="Adm,Stu"/>
<deny users="*" />
</authorization>
</system.web>
</location>
<location path="Home">
<system.web>
<authorization>
<allow roles="Adm,Stu,oth"/>
<deny users="*" />
</authorization>
</system.web>
</location>

网站。地图

Site.map

<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="" title="Home" description="" roles="Adm,Stu,Oth">
<siteMapNode url="Home.aspx" title="Home" description="Home Page" roles="Adm,Stu,Oth"></siteMapNode>
<siteMapNode url="javascript:;" title="Administrator" description="Administrator" roles="Adm">
<siteMapNode url ="Admin_page1.aspx" title="Admin1" description="Admin1" roles="Adm"></siteMapNode>
<siteMapNode url ="Admin_page2.aspx" title="Admin2" description="Admin2" roles="Adm"></siteMapNode>
</siteMapNode>
<siteMapNode url="javascript1:;" title="Student" description="Student" roles="Adm,Stu">
<siteMapNode url ="Student_Page1.aspx" title="StudentPage1" description="StudentPage1" roles="Adm,Stu"></siteMapNode>
<siteMapNode url ="Student_Page2.aspx" title="StudentPage2" description="StudentPage2" roles="Adm,Stu"></siteMapNode>
<siteMapNode url ="Student_Page3.aspx" title="StudentPage3" description="StudentPage3" roles="Adm,Stu"></siteMapNode>
</siteMapNode>
<siteMapNode url ="Lesson.aspx" title="Lesson" description="Lesson" roles="Adm,Stu,Oth"></siteMapNode>
<siteMapNode title="Users" description="Users" roles="Adm,Stu,Oth"></siteMapNode>
<siteMapNode title="Contact" description="Contact" roles="Adm,Stu,Oth"></siteMapNode>
</siteMapNode>
</siteMap>

我正在努力解决上述代码,以获取基于特定角色的菜单...



这在我的项目中最重要。



请愿。帮助



我的尝试:



工作代码



i am struggling the above code to get the menu for particular role based...

This most important in my project.

pls. help

What I have tried:

Working code

Dim arr As String() = {"Stu"}
HttpContext.Current.User = New GenericPrincipal(HttpContext.Current.User.Identity, arr)





菜单看起来很完美。



不工作的代码





menu will be appearing perfect.

Not working code

Dim arr As String() = {Session("Stu")}
HttpContext.Current.User = New GenericPrincipal(HttpContext.Current.User.Identity, arr)





会话值将通过,但是,菜单wil我没有出现。



以下是我的代码





Session value will be passing but, menu will not appear.

below is my code

<location path="Administrator">
<system.web>
<authorization>
<allow roles="Adm" />
<deny users="*" />
</authorization>
</system.web>
</location>
<location path="Student">
<system.web>
<authorization>
<allow roles="Adm,Stu" />
<deny users="*" />
</authorization>
</system.web>
</location>
<location path="Home">
<system.web>
<authorization>
<allow roles="Adm,Stu,oth" />
<deny users="*" />
</authorization>
</system.web>
</location>



Site.map


Site.map

<sitemap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0">
<sitemapnode url="" title="Home" description="" roles="Adm,Stu,Oth">
<sitemapnode url="Home.aspx" title="Home" description="Home Page" roles="Adm,Stu,Oth"></sitemapnode>
<sitemapnode url="javascript:;" title="Administrator" description="Administrator" roles="Adm">
<sitemapnode url="Admin_page1.aspx" title="Admin1" description="Admin1" roles="Adm"></sitemapnode>
<sitemapnode url="Admin_page2.aspx" title="Admin2" description="Admin2" roles="Adm"></sitemapnode>
</sitemapnode>
<sitemapnode url="javascript1:;" title="Student" description="Student" roles="Adm,Stu">
<sitemapnode url="Student_Page1.aspx" title="StudentPage1" description="StudentPage1" roles="Adm,Stu"></sitemapnode>
<sitemapnode url="Student_Page2.aspx" title="StudentPage2" description="StudentPage2" roles="Adm,Stu"></sitemapnode>
<sitemapnode url="Student_Page3.aspx" title="StudentPage3" description="StudentPage3" roles="Adm,Stu"></sitemapnode>
</sitemapnode>
<sitemapnode url="Lesson.aspx" title="Lesson" description="Lesson" roles="Adm,Stu,Oth"></sitemapnode>
<sitemapnode title="Users" description="Users" roles="Adm,Stu,Oth"></sitemapnode>
<sitemapnode title="Contact" description="Contact" roles="Adm,Stu,Oth"></sitemapnode>
</sitemapnode>
</sitemap>

推荐答案

Thanks for Excellent clues...i used char instead of varchar..
it occupies two additional empty spaces..now i changed to varchar.
Now its working.
Thanks for your valuable solution.


这篇关于Httpcontext.current.user&quot; role&quot;不正常。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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