|
I'm trying to protect one of my classes using PrincipalPermissionAttribute. I'm setting it to only allow the code to execute only if a specific user is trying to run it.
Here is the class declaration:
[PrincipalPermissionAttribute(SecurityAction.Demand, Authenticated:=True, name:="MYDOMAIN\\Mauricio")] public class foo
This code works fine but the problem is that it allows the usage of an GenericPrincipal object and I want it to use a WindowsPrincipal object. Allow it to use a GenericPrincipal will anyone to create a GenericPrincipal with that user name and execute the code. Like this:
GenericIdentity oIdent = new GenericIdentity("MYDOMAIN\\Mauricio", "NTLM");
GenericPrincipal oPrinc = new GenericPrincipal(oPrinc, null);
foo oFoo = new foo();
My question is: is there anyone to demand that a code only accepts WindowsPrincipals, and don't accept GenericPrincipals ?
thanks
Mauricio Ritter - Brazil
Sonorking now: 100.13560 MRitter
English is not my native language so, if you find any spelling erros in my posts, please let me know.
|
|
|
|
|
The only way you'll be able to do this is to extend the PrincipalPermission and PrincipalPermissionAttribute classes, or create your own. You could do the very same things, except check the Type against WindowsPrincipal that you get back from Thread.CurrentPrincipal . The current implementation doesn't care about the Type, so long as it implements IPrincipal .
If you want to know exactly what the current classes mentioned above are doing, you can use ildasm.exe that ships with the .NET Framework SDK if you know IL (and it wouldn't hurt to know anyway), or use a good decompiler like .NET Reflector[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have 2 panels, one docked to the left and the other docked to the bottom. I hide the left panel on startup but during runtime when i show it, i "pushed" the bottom panel to make room for itself. How can i prevent this. i.e. The left panel should be above the bottom panel.
<font=arial>Weiye Chen
When pursuing your dreams, don't forget to enjoy your life...
|
|
|
|
|
It's all about the order in which controls are added. Controls that are added first take precedence when docking over controls that are added later. When using Control/ControlCollection.AddRange , you need to add these in reverse order. How exactly are you "hiding" this control?
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Yes, i am adding them in the reverse order.
this.Controls.AddRange(new System.Windows.Forms.Control[] { this.panelLeft, this.panelBottom, ...});
Heath Stewart wrote:
How exactly are you "hiding" this control?
In the designer, both panels' Visible flags are set to false. In my application, there are 2 toggle buttons each calling the Hide() and Show() methods of the panels.
<font=arial>Weiye Chen
When pursuing your dreams, don't forget to enjoy your life...
|
|
|
|
|
I'm not sure if this will work, but try re-creating the handle for each control after changing the visibility of one (perhaps override OnVisibleChanged and doing it from within there after the call to base.OnVisibleChanged ). Since it appears that the control is re-created when changing the visibility of the current control, you could always handle the VisibleChanged event of the other control and re-create your own handle as well.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I just got it to work by inserting another control between the 2 panels during AddRange(...)
this.Controls.AddRange(new System.Windows.Forms.Control[] { this.panelLeft, this.progressBar, this.panelBottom, ...});
But this doesn't make sense. The progress bar is located far away from the panels. Ah, never mind.... Thanks anyway...
<font=arial>Weiye Chen
When pursuing your dreams, don't forget to enjoy your life...
|
|
|
|
|
Deal all ,
in win32 API we can get a control HDC from its handel then we can use that hdc as a sourec for drawing functions like bitblt , streatchblt ...
but in .net farmework how can a do a simmilar jop by using GDI+ where any image drawing function use just the iamge object ???
Regs.
Mhmoud Rawas
------------
Software Eng.
|
|
|
|
|
I am not sure if this is what u wanted:
Graphics graphics = Graphics.FromHwnd(MyControl.Handle);
<font=arial>Weiye Chen
When pursuing your dreams, don't forget to enjoy your life...
|
|
|
|
|
Dear Sir,
Thanks for help But this inforamtion not usefull for my question, let me giv you an example,
if you like to capture the desktop in win32 API you can call
SourceHdc = GetDC(GetDesktopWindow())
then to draw the picture you can use
BitBlt ( TargetHDC , SourceHDC , 0 , 0 ....
so how can i do it in GDI+ without using HDC
Mhmoud Rawas
------------
Software Eng.
|
|
|
|
|
Or use the CreateGraphics method inherited from Control . You can also override OnPaint in a Control derivative or handle the Paint event on a Control derivative outside that class (like by its container).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Dear Sir,
Thanks for help But this inforamtion not usefull for my question, let me giv you an example,
if you like to capture the desktop in win32 API you can call
SourceHdc = GetDC(GetDesktopWindow())
then to draw the picture you can use
BitBlt ( TargetHDC , SourceHDC , 0 , 0 ....
so how can i do it in GDI+ without using HDC
Mhmoud Rawas
------------
Software Eng.
|
|
|
|
|
GDI+ still uses handles. As the first reply mentioned, you can use Graphics.FromHwnd . Since you're not going to find a method that equates to BitBlt , you're most likely going to have to get an IntPtr representing the HDC from Graphics.GetHdc (call Graphics.ReleaseHdc when finished with the HDC ) anyway. You could also skip this overhead and P/Invoke the GetDC API, passing Control.Handle that is the HWND . This type of solution is very common. Handles are still very much used in the implementations of every Windows Forms control, and many other classes (like ImageList ).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
so you mean that we could not throw WIN32 API down and depend just on .Net classes, ...
No problem thanks for help again
Mhmoud Rawas
------------
Software Eng.
|
|
|
|
|
first thanks for you
and i hope to help me again i create managed c++ class library and used com in it when i compiled it any errors not found but when i build the library this error found
(unresolved token IID_IACCESSCONTROLENTRY)
|
|
|
|
|
|
Dear All,
I want to capture the keycode from keyboard buffer in VB.Net or C# Compact Framework.
Actually, I want to make a TSR(Terminate And Stay Resident) utility
which continuously look at the key strocks of keyboard and as soon as
a special key combination is pressed, it will invoke a function to
perform a series of actions.
For this purpose, I need to capture the keycode at system level not at
form level. So, how can i get keycode from keyboard buffer directly?
Tell me about some API for this purpose.
Regards,
Muhammad Arif
|
|
|
|
|
|
Dear Mazy,
There are two issues in the link you provided
1- This is for .NET Framework not for .NET Compact Framework
2- This code is for Mouse hooking not for keyboard
Please reply me for the code related to keyboard and written in .net compact framework.
Regards,
Muhammad Arif
|
|
|
|
|
aliarifpk wrote:
1- This is for .NET Framework not for .NET Compact Framework
Oh,sorry for that I didn't take attention to it.
aliarifpk wrote:
2- This code is for Mouse hooking not for keyboard
They follow the same procedure, you can find out yourself when you learn one.
Mazy
"A bank is a place that will lend you money if you can prove that you don't need it." - Bob Hope
|
|
|
|
|
Dear Mazy,
I am working on this task for last three days and the API's in .Net Framwork doesn't supported in .Net Compact Framework. That's why I am looking for some alternated which read the keyboard buffer and yet searching .... If someone has done this ... please let me know
Regards,
Muhammad Arif
|
|
|
|
|
Windows CE doesn't support message hooks. Hooking the keyboard isn't possible like it is under Windows 9x/2000/XP/2003.
RageInTheMachine9532
|
|
|
|
|
Dear Dave,
Can you provide me some authenticated URL which agree with your argument that Windows CE doesn't support hooking? I have to have a proof to my client for this argument.
Arif
Muhammad Arif
|
|
|
|
|
|
aliarifpk wrote:
This is for .NET Framework not for .NET Compact Framework
I don't think it make difference cause you have to call win32 API as you can see in that article, so I think you can use those API there too.
Mazy
"A bank is a place that will lend you money if you can prove that you don't need it." - Bob Hope
|
|
|
|