Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Security > check if user is the one specified in <location path="...

Reply
Thread Tools

check if user is the one specified in <location path="...

 
 
zino66
Guest
Posts: n/a
 
      03-10-2010
In an intranet asp.net application I have the following in the web config:

<authentication mode="Windows" />

<location path="AdministrationFolder">
<system.web>
<authorization>
<allow users="John"/>
<allow users="David"/>
<allow users="Eric"/>
<deny users="*"/>
</authorization>
</system.web>
</location>

The "Default.aspx" page is accessible to everybody.
I have a link <a href=Administration.aspx>Administration</a> on this page,
which I need it to be visible only if the user is one of those specified in
"<location path=....>" (If user = in (John, David, Eric) then, display the
link.)



How can I check if the logged user is one of the mentioned users above ?


 
Reply With Quote
 
 
 
 
Joe Kaplan
Guest
Posts: n/a
 
      03-10-2010
The identity information that the UrlAuthorizationModule (the thing taht
consumes that particular piece of XML web.config) examines the
HttpContext.User property, specifically the .Identity.Name property and the
..IsInRole method to compare against user name and role membership, so you
can do the same thing programmatically in your code to conditionally display
specific markup.

--
Joe Kaplan-MS MVP Directory Services Programming
Co-author of "The .NET Developer's Guide to Directory Services Programming"
http://www.directoryprogramming.net
"zino66" <> wrote in message
news:BA914AEF-61C7-4892-B5E3-...
> In an intranet asp.net application I have the following in the web config:
>
> <authentication mode="Windows" />
>
> <location path="AdministrationFolder">
> <system.web>
> <authorization>
> <allow users="John"/>
> <allow users="David"/>
> <allow users="Eric"/>
> <deny users="*"/>
> </authorization>
> </system.web>
> </location>
>
> The "Default.aspx" page is accessible to everybody.
> I have a link <a href=Administration.aspx>Administration</a> on this page,
> which I need it to be visible only if the user is one of those specified
> in
> "<location path=....>" (If user = in (John, David, Eric) then, display
> the
> link.)
>
>
>
> How can I check if the logged user is one of the mentioned users above ?
>
>


 
Reply With Quote
 
 
 
 
zino66
Guest
Posts: n/a
 
      03-11-2010
now I'm able to check the logged user name, but I need to compare it to the
one stored in <location path=....
<allow users='john'........

so, in the "Default.aspx" page, which is available to anybody (not only
'John',....),
I wrote:
Dim _as_ As Web.Configuration.AuthorizationSection =
Web.Configuration.WebConfigurationManager.GetSecti on("system.web/authorization", "~/Administration")

but I'm getting this error:
"The attribute 'users' has been locked in a higher level configuration"

I understand that accessing the config file in an already protected folder
from an unprotected page sound non-sense, but is there a way to work around
this ?

thanks for help


"Joe Kaplan" wrote:

> The identity information that the UrlAuthorizationModule (the thing taht
> consumes that particular piece of XML web.config) examines the
> HttpContext.User property, specifically the .Identity.Name property and the
> ..IsInRole method to compare against user name and role membership, so you
> can do the same thing programmatically in your code to conditionally display
> specific markup.
>
> --
> Joe Kaplan-MS MVP Directory Services Programming
> Co-author of "The .NET Developer's Guide to Directory Services Programming"
> http://www.directoryprogramming.net
> "zino66" <> wrote in message
> news:BA914AEF-61C7-4892-B5E3-...
> > In an intranet asp.net application I have the following in the web config:
> >
> > <authentication mode="Windows" />
> >
> > <location path="AdministrationFolder">
> > <system.web>
> > <authorization>
> > <allow users="John"/>
> > <allow users="David"/>
> > <allow users="Eric"/>
> > <deny users="*"/>
> > </authorization>
> > </system.web>
> > </location>
> >
> > The "Default.aspx" page is accessible to everybody.
> > I have a link <a href=Administration.aspx>Administration</a> on this page,
> > which I need it to be visible only if the user is one of those specified
> > in
> > "<location path=....>" (If user = in (John, David, Eric) then, display
> > the
> > link.)
> >
> >
> >
> > How can I check if the logged user is one of the mentioned users above ?
> >
> >

>
> .
>

 
Reply With Quote
 
Joe Kaplan
Guest
Posts: n/a
 
      03-12-2010
If I were solving the problem, I'd approach it differently.

I'd create a mechanism to put these users in a role called "Admin" or
something like that and then hard code the configuration section and your
security trimming UI code to just check that.

To generate a role for a user on the fly, you can hook the authenticate
event in global.asax (or something similar) and just issue an new
GenericPrincipal for the authenticated user that add specific users to a
role. You can create a custom configuration value of your own choosing to
determine which users are in the admin role or not.

I'm not sure what the recommended method to read the configuration file
directly is but it seems that ASP.NET does not want you doing it the way you
are trying right now.

--
Joe Kaplan-MS MVP Directory Services Programming
Co-author of "The .NET Developer's Guide to Directory Services Programming"
http://www.directoryprogramming.net
"zino66" <> wrote in message
news:4CBD42B0-747F-4C98-9F56-...
> now I'm able to check the logged user name, but I need to compare it to
> the
> one stored in <location path=....
> <allow users='john'........
>
> so, in the "Default.aspx" page, which is available to anybody (not only
> 'John',....),
> I wrote:
> Dim _as_ As Web.Configuration.AuthorizationSection =
> Web.Configuration.WebConfigurationManager.GetSecti on("system.web/authorization",
> "~/Administration")
>
> but I'm getting this error:
> "The attribute 'users' has been locked in a higher level configuration"
>
> I understand that accessing the config file in an already protected folder
> from an unprotected page sound non-sense, but is there a way to work
> around
> this ?
>
> thanks for help
>
>
> "Joe Kaplan" wrote:
>
>> The identity information that the UrlAuthorizationModule (the thing taht
>> consumes that particular piece of XML web.config) examines the
>> HttpContext.User property, specifically the .Identity.Name property and
>> the
>> ..IsInRole method to compare against user name and role membership, so
>> you
>> can do the same thing programmatically in your code to conditionally
>> display
>> specific markup.
>>
>> --
>> Joe Kaplan-MS MVP Directory Services Programming
>> Co-author of "The .NET Developer's Guide to Directory Services
>> Programming"
>> http://www.directoryprogramming.net
>> "zino66" <> wrote in message
>> news:BA914AEF-61C7-4892-B5E3-...
>> > In an intranet asp.net application I have the following in the web
>> > config:
>> >
>> > <authentication mode="Windows" />
>> >
>> > <location path="AdministrationFolder">
>> > <system.web>
>> > <authorization>
>> > <allow users="John"/>
>> > <allow users="David"/>
>> > <allow users="Eric"/>
>> > <deny users="*"/>
>> > </authorization>
>> > </system.web>
>> > </location>
>> >
>> > The "Default.aspx" page is accessible to everybody.
>> > I have a link <a href=Administration.aspx>Administration</a> on this
>> > page,
>> > which I need it to be visible only if the user is one of those
>> > specified
>> > in
>> > "<location path=....>" (If user = in (John, David, Eric) then, display
>> > the
>> > link.)
>> >
>> >
>> >
>> > How can I check if the logged user is one of the mentioned users above
>> > ?
>> >
>> >

>>
>> .
>>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to check whether user put a check in a toolbox CheckBox contro JB ASP .Net 1 08-26-2009 11:18 PM
RadioButtonList does not allow you to select a ListItem other than the first one that has a specified value Nathan Sokalski ASP .Net 1 11-28-2007 02:07 AM
Parser Error Message: Could not load file or assembly 'AjaxControlToolkit' or one of its dependencies. The system cannot find the file specified. hifiger2004 ASP .Net Web Controls 1 08-30-2007 04:12 PM
Check One CheckBox To Check All CheckBoxes rn5a@rediffmail.com ASP .Net 10 12-05-2006 11:35 AM
how to selecet check box in the data grid ?? only one check box mit ASP .Net 1 01-25-2006 06:47 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57