Re: security permissions for creating a file

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



"Mark" <Scollop027@xxxxxxx> wrote in message
news:dcpobo$pvt$00$1@xxxxxxxxxxxxxxxxxxxx
> hi,
>
> what I am trying:
>
> 1. I create a file x.cs with notepad nothing more than a main
<snip>
> 2. built it with csc.exe x.cs and got a x.exe
> 3. executing x.exe on commandline (local dir, no shares, as admin, no
> domain, simple way)

If you're running the exe from a local hard drive (as opposed to somewhere
on your network), it sounds like you might have modified your CAS policy.
To verify what permissions your executable is being assigned under your
current CAS policy, follow the steps listed in the "How can I test my policy
changes?" section at
http://msdn.microsoft.com/library/en-us/dnnetsec/html/entsecpoladmin.asp.
If your assembly is local, and it's granted anything other than an
unrestricted permission set, your CAS policy has been modified from its
default configuration.

If you are running with modified policy, was it a deliberate change or not?
If it wasn't deliberate, you might want to simply revert to the default
configuration (after backing up your current configuration). If it was
deliberate, then adding a new code group to allow your application to run as
desired might be a better approach.

If your assembly is granted unrestricted permissions under policy, might the
problem stem from use of assembly-level permissions attributes? In
particular, might you be using any attributes with
SecurityAction.RequestOptional?


> 4. got exception - I guess .NET told me that this application is not safe
> writing files.
> Request for the permission of type
> System.Security.Permissions.FileIOPermission, mscorlib,
> Version=1.0.5000.0,
> Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.
>
> regards
> Mark
>
> "Nicholas Paldino [.NET/C# MVP]" <mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx> schrieb
> im Newsbeitrag news:e2ysb93lFHA.2080@xxxxxxxxxxxxxxxxxxxxxxx
>> Are you sure that the security exception is for opening the file
>> then?
>> Where is the application loaded from? Are you running it from a network
>> share, or the internet? If so, then the application is going to be
> granted
>> a limited permission set.
>>
>>
>> --
>> - Nicholas Paldino [.NET/C# MVP]
>> - mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx
>>
>> "Mark" <Scollop027@xxxxxxx> wrote in message
>> news:dco6ob$ig6$01$1@xxxxxxxxxxxxxxxxxxxx
>> > Hi Nicholas,
>> >
>> > I tried a console application and as admin I have no restriction in any
>> > directory.
>> >
>> > regards Mark
>> >
>> >
>> >
>> > "Nicholas Paldino [.NET/C# MVP]" <mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
> schrieb
>> > im Newsbeitrag news:eszHSt3lFHA.3256@xxxxxxxxxxxxxxxxxxxxxxx
>> >> Mark,
>> >>
>> >> You get this exception because you don't have rights to create or
>> >> open
>> >> the file in the directory that it is set in. You need to try and
> create
>> > the
>> >> file in a directory that you have rights to, or, if the file exists,
>> >> check
>> >> the rights on the file to make sure that you can open it for writing.
>> >>
>> >> Hope this helps.
>> >>
>> >>
>> >> --
>> >> - Nicholas Paldino [.NET/C# MVP]
>> >> - mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx
>> >>
>> >> "Mark" <Scollop027@xxxxxxx> wrote in message
>> >> news:dco3i4$btq$01$1@xxxxxxxxxxxxxxxxxxxx
>> >> > Hello,
>> >> >
>> >> > in a simple console application I try to create a file with some
>> >> > code
>> >> > like:
>> >> >
>> >> > FileStream file = new FileStream("test.txt", FileMode.OpenOrCreate,
>> >> > FileAccess.Write);
>> >> > StreamWriter sw = new StreamWriter(file);
>> >> > sw.Write("Hello");
>> >> > sw.Close();
>> >> > file.Close();
>> >> >
>> >> > I will get an error System.Security.SecurityException
>> >> >
>> >> > Are there only one way to avoid this and how this can be done?
>> >> >
>> >> > Thanks and regards
>> >> > Mark
>> >> >
>> >> >
>> >>
>> >>
>> >
>> >
>>
>>
>
>


.



Relevant Pages

  • Re: Appl. Security Problems
    ... "Nicole Calinoiu" wrote: ... > are only allowed to attempt to adjust the permissions at the user level. ... >> What do I or, my IT person, need to do to change security policy? ... > instructions on how to modify the CAS policy for this scenario. ...
    (microsoft.public.dotnet.security)
  • Re: Appl. Security Problems
    ... Are there instructions on how trust a directorory and the files within it. ... > are only allowed to attempt to adjust the permissions at the user level. ... >> What do I or, my IT person, need to do to change security policy? ... > instructions on how to modify the CAS policy for this scenario. ...
    (microsoft.public.dotnet.security)
  • Re: Loading an Assembly from a URL
    ... The downlading assembly will need the WebPermission. ... The downloaded assembly will run with permissions relevant to the evidence it presents to CAS policy. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Problems with MS Access data source
    ... > Same on both systems or correct for Server 2003? ... The NTFS permissions are the same on both systems, ... Web app does not use ISAPI ... which part in its configuration can be the ...
    (microsoft.public.inetserver.iis.security)
  • Re: Environment.CommandLine Security Exception
    ... app from a *network* share. ... > Configuration tool or CASPOL. ... >>> the appropriate permissions, the program should run ...
    (microsoft.public.dotnet.security)