469,283 Members | 2,303 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,283 developers. It's quick & easy.

Authentication and user based content

Hi,

I've created a small application with some user-authentication and roles.

I would like to show/hide some navigation parts based on the users role.

Could someone please tell me what the best solution is?

Do I have to create different pages for each role and check the users role
when logged in?

Thanx

Kind regards

John
Jun 27 '08 #1
4 1226
You can use different sitemaps for different roles.

If you have 2 providers in the web.config

<siteMap enabled="true">
<providers>
<add name="Role1SiteMapProvider" description="SiteMap for role 1."
type="System.Web.XmlSiteMapProvider"
siteMapFile="Roles/Role1/Role1.sitemap" />
<add name="Role2SiteMapProvider" description="SiteMap for role 2."
type="System.Web.XmlSiteMapProvider"
siteMapFile="Roles/Role2/Role2.sitemap" />
</providers>
</siteMap>

you can set SiteMapProvider property for navigation controls in the code to
either Role1SiteMapProvider or Role2SiteMapProvider depending on the user
role.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"John Devlon" <Jo********@hotmail.comwrote in message
news:OJ******************************@dommel.com.. .
Hi,

I've created a small application with some user-authentication and roles.

I would like to show/hide some navigation parts based on the users role.

Could someone please tell me what the best solution is?

Do I have to create different pages for each role and check the users
role when logged in?

Thanx

Kind regards

John

Jun 27 '08 #2
There are two good solutions here (which can be combined).

The first is to set up roles in the sitemap file. You have to set roles at
all levels for this to work (not sure why), but roles="*" is valid.

If you set up the SiteMap Provider to use the security trimmings, you will
end up with it respecting security in web.config files at different levels.
Set up your secure bits deeper (in folders) and set a web.config that only
allows specified roles. With security trimmings on, it will not allow the
menu to see the pages if the user is not in role(s).

So, here it is:

1. Most secure: Set web.configs with proper security and turn security
trimmings on in the main web.config under the SiteMap provider
2. Can work in most situations: Add roles to sitemap file

One caveat:
Have to use the Microsoft Membership bits, even if a custom provider, unless
you want to build the entire security model yourself.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://gregorybeamer.spaces.live.com/lists/feed.rss

or just read it:
http://gregorybeamer.spaces.live.com/

*************************************************
| Think outside the box!
|
*************************************************
"John Devlon" <Jo********@hotmail.comwrote in message
news:OJ******************************@dommel.com.. .
Hi,

I've created a small application with some user-authentication and roles.

I would like to show/hide some navigation parts based on the users role.

Could someone please tell me what the best solution is?

Do I have to create different pages for each role and check the users
role when logged in?

Thanx

Kind regards

John

Jun 27 '08 #3
Thanx for your respons....

However, I think it's not something I can use...

I've created a navigation system with pictures and placed them in a
table....
Only some rows have to be shown with each role...

Can I show/hide elements like tables and pictures depending on the role?

Thanx

John

"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgschree f in
bericht news:eW**************@TK2MSFTNGP04.phx.gbl...
You can use different sitemaps for different roles.

If you have 2 providers in the web.config

<siteMap enabled="true">
<providers>
<add name="Role1SiteMapProvider" description="SiteMap for role 1."
type="System.Web.XmlSiteMapProvider"
siteMapFile="Roles/Role1/Role1.sitemap" />
<add name="Role2SiteMapProvider" description="SiteMap for role 2."
type="System.Web.XmlSiteMapProvider"
siteMapFile="Roles/Role2/Role2.sitemap" />
</providers>
</siteMap>

you can set SiteMapProvider property for navigation controls in the code
to either Role1SiteMapProvider or Role2SiteMapProvider depending on the
user role.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"John Devlon" <Jo********@hotmail.comwrote in message
news:OJ******************************@dommel.com.. .
>Hi,

I've created a small application with some user-authentication and roles.

I would like to show/hide some navigation parts based on the users role.

Could someone please tell me what the best solution is?

Do I have to create different pages for each role and check the users
role when logged in?

Thanx

Kind regards

John


Jun 27 '08 #4
You can always check what is the role for the current user and set visual
properties for your controls accordingly.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"John Devlon" <Jo********@hotmail.comwrote in message
news:8j*******************@newsfe10.ams2...
Thanx for your respons....

However, I think it's not something I can use...

I've created a navigation system with pictures and placed them in a
table....
Only some rows have to be shown with each role...

Can I show/hide elements like tables and pictures depending on the role?

Thanx

John

"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgschree f in
bericht news:eW**************@TK2MSFTNGP04.phx.gbl...
>You can use different sitemaps for different roles.

If you have 2 providers in the web.config

<siteMap enabled="true">
<providers>
<add name="Role1SiteMapProvider" description="SiteMap for role 1."
type="System.Web.XmlSiteMapProvider"
siteMapFile="Roles/Role1/Role1.sitemap" />
<add name="Role2SiteMapProvider" description="SiteMap for role 2."
type="System.Web.XmlSiteMapProvider"
siteMapFile="Roles/Role2/Role2.sitemap" />
</providers>
</siteMap>

you can set SiteMapProvider property for navigation controls in the code
to either Role1SiteMapProvider or Role2SiteMapProvider depending on the
user role.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"John Devlon" <Jo********@hotmail.comwrote in message
news:OJ******************************@dommel.com. ..
>>Hi,

I've created a small application with some user-authentication and
roles.

I would like to show/hide some navigation parts based on the users role.

Could someone please tell me what the best solution is?

Do I have to create different pages for each role and check the users
role when logged in?

Thanx

Kind regards

John



Jun 27 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by dmcconkey | last post: by
5 posts views Thread by Maziar Aflatoun | last post: by
1 post views Thread by Shapper | last post: by
11 posts views Thread by xenophon | last post: by
1 post views Thread by Mark Olbert | last post: by
5 posts views Thread by Rory Becker | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.