View Full Version : WindowsPrincipal Question
Hey,
I'm trying to play around with the WindowsPrincipal object with a view to implementing some intranet security using active directory, and after a bit of scouting around i came across an article in the msdn.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/secnetlpMSDN.asp
However near the bottom of the page this sample code is given which as assumed was vbscript
WindowsPrincipal wp = (HttpContext.Current.User as
WindowsPrincipal);
if ( wp.IsInRole("Manager") )
{
// User is authorized to perform manager-specific functionality
}
Straight away i knew this wasnt going to work and sure enough it returned an error at the AS word in the first line.
I tried playing around with it to match what i know of how asp is usually structured and came up with this.
Dim wp
wp = CreateObject(HttpContext.Current.User)
if ( wp.IsInRole("Manager") ) then
end if
However this doesn't work either. Don't know if im on the right track here but any help would be appreciated.
Cheers.
afterburn
11-23-2004, 10:45 AM
Originally posted by Ally
Hey,
I'm trying to play around with the WindowsPrincipal object with a view to implementing some intranet security using active directory, and after a bit of scouting around i came across an article in the msdn.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/secnetlpMSDN.asp
However near the bottom of the page this sample code is given which as assumed was vbscript
WindowsPrincipal wp = (HttpContext.Current.User as
WindowsPrincipal);
if ( wp.IsInRole("Manager") )
{
// User is authorized to perform manager-specific functionality
}
Straight away i knew this wasnt going to work and sure enough it returned an error at the AS word in the first line.
I tried playing around with it to match what i know of how asp is usually structured and came up with this.
Dim wp
wp = CreateObject(HttpContext.Current.User)
if ( wp.IsInRole("Manager") ) then
end if
However this doesn't work either. Don't know if im on the right track here but any help would be appreciated.
Cheers.
You must assign the role correctly. The code the provided is correct. You must assign the Role the user is in. .net knows nothing about ADSI or its groups and Users.
The role section aside, the variable declaration doesnt even work. Obviously theres just something i havnt done but simply putting that code within <% %> tags at the top of the page still generates the following error
Microsoft VBScript compilation error '800a03ee'
Expected ')'
/allytest.asp, line 2
WindowsPrincipal wp = (HttpContext.Current.User as WindowsPrincipal);
------------------------------------------------^
VBScript and a semi-colon?
Well thats what happens when you assume ASP.NET is just the same as ASP except with more stuff. Codebehind files ? Pre-Compiled DLL's ? LOL. Looks like i have a lot of reading to do before i start tampering in things like that.
Cheers for your patience guys i might be back in a few days ;)
Indeed... not only because you need a .aspx extension for ASP.NET, but also because the example is written in C# and not VB! ASP.NET can be written in either language, but you must also be aware of the differences between VBScript and VB. As someone who only knew VBScript, i found the transition easy, and i find VB syntax to be somewhat better.
Have fun learning ASP.NET, i am certainly enjoying doing new projects with it. I have found however that some of the simpler things you could do in ASP are a bit tricky to do with .NET... just comes with the territory i guess. The advantages outweigh the shortcomings though, by far.
afterburn
11-25-2004, 11:31 AM
Originally posted by Ally
The role section aside, the variable declaration doesnt even work. Obviously theres just something i havnt done but simply putting that code within <% %> tags at the top of the page still generates the following error
Microsoft VBScript compilation error '800a03ee'
Expected ')'
/allytest.asp, line 2
WindowsPrincipal wp = (HttpContext.Current.User as WindowsPrincipal);
------------------------------------------------^
That error is a result of ASP parsing engine trying to do it.
That is because IIS does not have the ASP.net Filter installed correctly.
You can install it by using the following in a command line
cd C:\Windows\Microsoft.net\Framework\vxxxxxx
where vxxxxxx is the version of the framework each of them co-exist in different folders
then typing the following in the command line
aspnet_iisreg -i
that will install it for ASP.net to parse the files correctly
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.