Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Controls / January 2006

Tip: Looking for answers? Try searching our database.

Copy from DataGridView needs permission?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jakob Lithner - 09 Jan 2006 15:19 GMT
I found an interesting property in the DataGridView control, named
ClipboardCopyMode.

When I run in Visual Studio Environment it works fine to highlight either a
cell or a row and copy it to the clipboard. It also works when I run the
application on my local drive, BUT when I run the application on an external
drive it does not work.

What kind of intricate permission is needed to allow a simple copy?
"Jeffrey Tan[MSFT]" - 10 Jan 2006 03:24 GMT
Hi jaklithn,

Thanks for your post.

Yes, I can reproduce out this issue. Actually, this is limited by .Net2.0
Code Access Security. Internally, when user pressed Ctrl+C key,
DataGridView will call DataGridView. ProcessInsertKey method to do the copy
operation. However, .Net2.0 placed a SecurityPermission check on this
method. Source listed below(from Reflector):

[SecurityPermission(SecurityAction.LinkDemand,
Flags=SecurityPermissionFlag.UnmanagedCode)]
protected bool ProcessInsertKey(Keys keyData)
{
     if ((((keyData & (Keys.Alt | (Keys.Control | Keys.Shift))) ==
Keys.Control) || (((keyData & (Keys.Alt | (Keys.Control | Keys.Shift))) ==
(Keys.Control | Keys.Shift)) && ((keyData & Keys.KeyCode) == Keys.C))) &&
(this.ClipboardCopyMode != DataGridViewClipboardCopyMode.Disable))
     {
           DataObject obj1 = this.GetClipboardContent();
           if (obj1 != null)
           {
                 Clipboard.SetDataObject(obj1);
                 return true;
           }
     }
     return false;
}
So, this is by design.

To workaround this problem, we can create a code group for our assembly,
then assign an extra SecurityPermission to this code group.

Hope this helps

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Signature

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Jakob Lithner - 10 Jan 2006 08:12 GMT
1) This means every user that wants to use this feature needs to do a manual
reconfiguration of security settings on their computers? Seems like overkill
to reach this very small and harmless feature.

2) I tried the configuration for the first time:
Runtime Security Policy - Machine - Code Groups
I added a new Code group under All_Code.
I added a new Permission set and added User Interface with full permission.
Applications
I added an application reference
Then I am stuck: How do I connect these settings? Where do I tell the
specified application assembly to use the specified Permission Setting?
"Jeffrey Tan[MSFT]" - 11 Jan 2006 02:35 GMT
Hi jaklithn,

Thanks for your feedback.

#1, yes, you are right. This is because of the principle of security.
Security is all about trust. Because our application runs in a network
share folder, it can not have all the trust as an application on local
disk.(Also, application from internet will have a much more restricted
trust). This is by design of .Net code access security. Maybe we can place
some hint information on the application to notify the end user to give
more "trust" to our application(that is give security configuration to your
application)

#2, when adding a code group, we should make sure our application fails in
the boundary of this code group, for example, we can use URL as a
condition, then we can associate our application URL with this code group.
After setting up an enough permission set, it will appear in the code group
permission set list. So we should first create the code group, then create
the code group, and select the new created permission set for this code
group.

For more information regarding .Net CAS, please refer to the link below:
"Understanding .NET Code Access Security"
http://www.codeproject.com/dotnet/UB_CAS_NET.asp

Hope this helps

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Signature

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Jakob Lithner - 12 Jan 2006 12:19 GMT
I find the .Net security concept hard to grasp. Do you really intend the end
users to make all those security configuarations manually on their own local
machines? I am a fairly experienced developer and I am quite lost myself.

I created a PermissionSet called ClipboardPermission and added a
UserInterface permission with the Grant Assemblies ... All Clipboard set.

I added this PermissionSet to the All_Code group. I know this is not
recomended, but just for the sake of testing. I still was not able to copy
from the GridView!

When I added the FullTrust PermissionSet to All_Code, then it worked.

Question: Are there more necessary permissions involved, apart from
AllClipboard?

My preliminary conclusion is: Don't bother to add nice features to your
application if they involve custom safety requirements. It is not worth the
labour.
"Jeffrey Tan[MSFT]" - 13 Jan 2006 06:42 GMT
Hi jaklithn,

Thanks for your feedback.

No, just as I pointed out in first reply, this issue is not constrained by
UIPermission, but by SecurityPermission with
SecurityPermissionFlag.UnmanagedCode. Look below:
[SecurityPermission(SecurityAction.LinkDemand,
Flags=SecurityPermissionFlag.UnmanagedCode)]

So we should assign Security permission to the code group. Select Security
permission in the left ¡°Available Permissions¡± listbox, then click Add>>,
we should check ¡°Allow calls to unmanaged assemblies¡± option then click
¡°Ok¡±.

Only partial trusted place running application will be constrained by .Net
CAS, such as internet, shared folder etc.., the local running app will be
full trusted.

Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Signature

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.