I have a fairly simple C# console app which copies files from a network
folder to a local folder. When the app resides on my local C: drive, it
runs just fine. However, when the app resides on a network drive, copying
the same files from the same source drive and to the same destination drive,
it gives me the following exception:
System.Security.SecurityException: Request for the permission of type
System.Security.Permissions.FileIOPermission, mscorlib, Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.
at System.Security.CodeAccessSecurityEngine.CheckHelp er(PermissionSet
grantedSet, PermissionSet deniedSet, CodeAccessPermission demand,
PermissionToken permToken)
at System.Security.CodeAccessSecurityEngine.Check(Per missionToken
permToken,CodeAccessPermission demand, StackCrawlMark& stackMark, Int32
checkFrames, Int32 unrestrictedOverride)
at System.Security.CodeAccessSecurityEngine.Check(Cod eAccessPermission
cap, StackCrawlMark& stackMark)
at System.Security.CodeAccessPermission.Demand()
at System.IO.DirectoryInfo..ctor(String path)
It seems as if it is assuming the rights of the remote server from which it
is running, even though the app is obviously running as a local process --
this makes absolutely no sense to me. Why does the app assume a totally
different set of permissions just because it resides in a different
location? To me, it seems like the permissions should only be driven by the
process from which it is running, and the identity that is active when
running the application.
Can someone explain to me why I am getting this error, and how I can get
around it so that I can have this app site on a network directory, and copy
files from that same directory to a local directory?
Thanks in advance.
Jerad 2 7963
Jerad,
You will want to look at Code Access Security. The rights that you have
are not only based on the identity that launched the process, but the the
code itself.
So, if code came from another place (a website, for example), and tried
to do something malicious, it couldn't even if it was running under you, as
administrator.
As a general rule, code that executes on your machine doesn't have any
limitations put on it. Code that is loaded from the network, or from a
website has less trust associated with it, and less permissions assigned to
it.
Now, you can change this, by identifying the code (by location, hash, or
strong name) and then assigning the appropriate permission set to the code.
However, this requires a conscious effort on your part. So in other words,
they let you shoot yourself in the foot if you want to, but you have to
agree to it, so you can't say it was anyone else's fault if something gets
wrecked. =)
You would do this in the .NET Framework configuration apps which are
found in Administrative Tools.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Jerad Rose" <no@spam.com> wrote in message
news:e9**************@TK2MSFTNGP03.phx.gbl... I have a fairly simple C# console app which copies files from a network folder to a local folder. When the app resides on my local C: drive, it runs just fine. However, when the app resides on a network drive, copying the same files from the same source drive and to the same destination drive, it gives me the following exception:
System.Security.SecurityException: Request for the permission of type System.Security.Permissions.FileIOPermission, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed. at System.Security.CodeAccessSecurityEngine.CheckHelp er(PermissionSet grantedSet, PermissionSet deniedSet, CodeAccessPermission demand, PermissionToken permToken) at System.Security.CodeAccessSecurityEngine.Check(Per missionToken permToken,CodeAccessPermission demand, StackCrawlMark& stackMark, Int32 checkFrames, Int32 unrestrictedOverride) at System.Security.CodeAccessSecurityEngine.Check(Cod eAccessPermission cap, StackCrawlMark& stackMark) at System.Security.CodeAccessPermission.Demand() at System.IO.DirectoryInfo..ctor(String path)
It seems as if it is assuming the rights of the remote server from which it is running, even though the app is obviously running as a local process -- this makes absolutely no sense to me. Why does the app assume a totally different set of permissions just because it resides in a different location? To me, it seems like the permissions should only be driven by the process from which it is running, and the identity that is active when running the application.
Can someone explain to me why I am getting this error, and how I can get around it so that I can have this app site on a network directory, and copy files from that same directory to a local directory?
Thanks in advance.
Jerad
Thanks for your response, Nicholas. I did make an attempt to get this
working using Code Access Security (after getting your feedback), but I was
unsuccessful. Unfortunately, I am under a deadline that does not give me
the luxery of time required to figure this out, considering the learning
curve and the fact that I have no prior experience with developing with Code
Access Security. We ultimately ended up going the dirty route of a batch
file to do our installation. By the way, this was for a deployment
application for some C# interop components we developed for use by a VB6
application.
Thanks again for your time and response.
Jerad
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2****************@TK2MSFTNGP04.phx.gbl... Jerad,
You will want to look at Code Access Security. The rights that you have are not only based on the identity that launched the process, but the the code itself.
So, if code came from another place (a website, for example), and tried to do something malicious, it couldn't even if it was running under you, as administrator.
As a general rule, code that executes on your machine doesn't have any limitations put on it. Code that is loaded from the network, or from a website has less trust associated with it, and less permissions assigned to it.
Now, you can change this, by identifying the code (by location, hash, or strong name) and then assigning the appropriate permission set to the code. However, this requires a conscious effort on your part. So in other words, they let you shoot yourself in the foot if you want to, but you have to agree to it, so you can't say it was anyone else's fault if something gets wrecked. =)
You would do this in the .NET Framework configuration apps which are found in Administrative Tools.
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"Jerad Rose" <no@spam.com> wrote in message news:e9**************@TK2MSFTNGP03.phx.gbl...I have a fairly simple C# console app which copies files from a network folder to a local folder. When the app resides on my local C: drive, it runs just fine. However, when the app resides on a network drive, copying the same files from the same source drive and to the same destination drive, it gives me the following exception:
System.Security.SecurityException: Request for the permission of type System.Security.Permissions.FileIOPermission, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed. at System.Security.CodeAccessSecurityEngine.CheckHelp er(PermissionSet grantedSet, PermissionSet deniedSet, CodeAccessPermission demand, PermissionToken permToken) at System.Security.CodeAccessSecurityEngine.Check(Per missionToken permToken,CodeAccessPermission demand, StackCrawlMark& stackMark, Int32 checkFrames, Int32 unrestrictedOverride) at System.Security.CodeAccessSecurityEngine.Check(Cod eAccessPermission cap, StackCrawlMark& stackMark) at System.Security.CodeAccessPermission.Demand() at System.IO.DirectoryInfo..ctor(String path)
It seems as if it is assuming the rights of the remote server from which it is running, even though the app is obviously running as a local process -- this makes absolutely no sense to me. Why does the app assume a totally different set of permissions just because it resides in a different location? To me, it seems like the permissions should only be driven by the process from which it is running, and the identity that is active when running the application.
Can someone explain to me why I am getting this error, and how I can get around it so that I can have this app site on a network directory, and copy files from that same directory to a local directory?
Thanks in advance.
Jerad
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Robert Tarantino |
last post by:
Hello,
I am trying to find a way to create a scheduled task or
service that will copy my local profile folders
under "Documents and settings" to a network drive. This
would allow me to restore...
|
by: Dan |
last post by:
We debug a VB.Net App that uses compact framework to a DAP Windows CE.Net
device.
When I debug I would like to only have the EXE copied down. Right now it
copies any referrences as well and...
|
by: surya |
last post by:
Hi,
I need to enable shadow copying network share folder assemblies. Currently
if the path is given as the network share folder path, shadow copying is not
enabled. Should something special be...
|
by: Raterus |
last post by:
Hi, I'm after this setup, and I'm just wondering if this is even feasible.
I'd like to store my asp.net project remotely, on a network drive (all the project files, everything), But I want to be...
|
by: Aaron Masten |
last post by:
Is there any way to force traffic from a particular Class C IP Subnet to the
Cluster Controller. The main reason I am asking is that we have a custom
ASP.NET Application that is hosted on the a...
| |
by: |
last post by:
Hello,
I have a program that starts a new thread to backup files
from a computer over the network to our server. The
problem is when it is copying the files you can hardly
navigate around in...
|
by: Frank Rizzo |
last post by:
Hello, my app needs to copy a file from local TEMP folder to network
share. The network share is accessible via a domain ID.
I am trying to call LogonUser API, then ImpersonateLoggedOnUser, then...
|
by: Sue |
last post by:
Hello
We have an application where the user would upload files (max size of
200 mb) from their client machine. This application will run on a web
server (its a web server which would be used by...
|
by: Mantorok |
last post by:
Hi all
C# v2.0
I want to update a server which is in our DMZ, to access this server I
always need to enter the admin user id and password.
I want to copy some files overnight to this server...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |