Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
VB
Dim arr As String() = {"Stu"}
HttpContext.Current.User = New GenericPrincipal(HttpContext.Current.User.Identity, arr)

menu will be appearing perfect.

Not working code
VB
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

HTML
<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
<?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

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


menu will be appearing perfect.

Not working code

VB
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

HTML
<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
HTML
<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>
Posted
Updated 21-Feb-16 17:59pm
v2
Comments
Richard Deeming 19-Feb-16 8:48am    
What value is stored in the session variable?
gani7787 20-Feb-16 1:15am    
session value coming from the database.
Getting the role from database in the login page and assign the value to session.
by default,session values are coming. but, not displaying the menu.

Database Table
------------------
Stu-number Role
----------- -----------
101 Adm --> Administrator
102 Stu --> Student
103 Oth --> Others
Richard Deeming 20-Feb-16 9:58am    
Yes, but WHAT is the value? When you debug your code and examine the value of Session["Stu"], does it contain the string Stu, or does it contain something else?
gani7787 21-Feb-16 4:39am    
it contains string("Stu"). Session value maintain properly. But,when it holds the value with httpcontext then menu will not be appearing.
gani7787 20-Feb-16 0:32am    
session value coming from the database.
Getting the role from database in the login page and assign the value to session.
by default,session values are coming. but, not displaying the menu.

Database Table
------------------
Stu-number Role
----------- -----------
101 Adm --> Administrator
102 Stu --> Student
103 Oth --> Others

1 solution

C#
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900