Home All Groups Group Topic Archive Search About

VS2005 Throws Security Exception when run from Network!?

Author
30 Aug 2006 9:10 AM
David++
Dear List,

I have developed an application in VS 2005. The application works fine when
run from the Local drive C:\ but when the application is run from a Network
Drive it throws a Security Exception. The Exception getting thrown is -

I would rather the user doesnt have to configure the app themselves so I
believe you can make the assemblies 'Strong-Named' and add a Public/Private
Key pair which can be modifed to setup the various security permissions? I
have generated a Public/Private Key pair, added it to my project, but what
next? How do I set these permissions?

Thanks for any help offered,

Best Regards,
David Ross

Author
30 Aug 2006 12:45 PM
Nicole Calinoiu
See http://blogs.msdn.com/shawnfa/archive/2003/06/20/57023.aspx for CAS
policy modification instructions.  However, given that this is a .NET 2.0
application, you may prefer to deploy as a ClickOnce application, which
would help avoid the need to deploy the policy modifications to the client
machines.



Show quoteHide quote
"David++" <Da***@discussions.microsoft.com> wrote in message
news:AC2E453E-7561-431D-8151-2290AAC848BC@microsoft.com...
> Dear List,
>
> I have developed an application in VS 2005. The application works fine
> when
> run from the Local drive C:\ but when the application is run from a
> Network
> Drive it throws a Security Exception. The Exception getting thrown is -
>
> I would rather the user doesnt have to configure the app themselves so I
> believe you can make the assemblies 'Strong-Named' and add a
> Public/Private
> Key pair which can be modifed to setup the various security permissions? I
> have generated a Public/Private Key pair, added it to my project, but what
> next? How do I set these permissions?
>
> Thanks for any help offered,
>
> Best Regards,
> David Ross
>
>
Author
31 Aug 2006 8:28 AM
David++
Show quote Hide quote
"Nicole Calinoiu" wrote:

> See http://blogs.msdn.com/shawnfa/archive/2003/06/20/57023.aspx for CAS
> policy modification instructions.  However, given that this is a .NET 2.0
> application, you may prefer to deploy as a ClickOnce application, which
> would help avoid the need to deploy the policy modifications to the client
> machines.
>
>
>
> "David++" <Da***@discussions.microsoft.com> wrote in message
> news:AC2E453E-7561-431D-8151-2290AAC848BC@microsoft.com...
> > Dear List,
> >
> > I have developed an application in VS 2005. The application works fine
> > when
> > run from the Local drive C:\ but when the application is run from a
> > Network
> > Drive it throws a Security Exception. The Exception getting thrown is -
> >
> > I would rather the user doesnt have to configure the app themselves so I
> > believe you can make the assemblies 'Strong-Named' and add a
> > Public/Private
> > Key pair which can be modifed to setup the various security permissions? I
> > have generated a Public/Private Key pair, added it to my project, but what
> > next? How do I set these permissions?
> >
> > Thanks for any help offered,
> >
> > Best Regards,
> > David Ross
> >

Thank you, I will look into that,

David
Author
1 Sep 2006 3:39 PM
David++
Hello again,

Ok, I've been trying to solve this for the last couple of days now and still
no joy. The error that is getting thrown is -

Request for the permission of type
'System.Security.Permissions.EnvironmentPermission, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

And if I click details it also says -

The Zone of the assembly that failed was:
Intranet

In the Project properties I have ran the 'Calculate Permissions' and it says
that to run the application must be 'Full Trust'. So I have tried deploying
as full trust and no joy. I have also built the application using Partial
Trust and excluded the EnvironmentPermission. Still no joy this way.

I have Signed the application with a Strong name and produced a strong name
key file. If I then build and place the exe of the application on the
Network, and also configure the Microsoft .NET 2.0 Framework Configuration by
adding a new group to the All_Code then this works. Is this correct? I'm new
to strong names and Microsoft .NET configuration. If I do this, is it
granting the securities to just my application? If so then this should be
acceptable.

Another option would be to simply 'turn off' the thing throwing the security
exception. However its still not clear for me how to do this..its not really
straight forward. I'm on VS 2005 if that helps.

Is there anything programmatically i can set in my application which means I
dont have to Configure anything externally?

Thanks for any further help,
Kinda confused here....

David
Author
5 Sep 2006 4:47 PM
Nicole Calinoiu
Show quote Hide quote
"David++" <Da***@discussions.microsoft.com> wrote in message
news:4CBBF8F9-22FB-483D-AFD4-B5063E05B2DE@microsoft.com...
> Hello again,
>
> Ok, I've been trying to solve this for the last couple of days now and
> still
> no joy. The error that is getting thrown is -
>
> Request for the permission of type
> 'System.Security.Permissions.EnvironmentPermission, mscorlib,
> Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
>
> And if I click details it also says -
>
> The Zone of the assembly that failed was:
> Intranet
>
> In the Project properties I have ran the 'Calculate Permissions' and it
> says
> that to run the application must be 'Full Trust'. So I have tried
> deploying
> as full trust and no joy.

Exactly what happened when you attempted to deploy as a fully trusted
ClickOnce app?  Were you running from the ClickOnce harness page or were you
trying to run the executable directly off a network share?  If the former,
were you prompted to elevate the assembly's permissions?


> I have also built the application using Partial
> Trust and excluded the EnvironmentPermission. Still no joy this way.

If the assembly is missing EnvirnmentPermssion, you need to include it, not
exclude it, when creating a partial trust ClickOnce manifest.




> I have Signed the application with a Strong name and produced a strong
> name
> key file. If I then build and place the exe of the application on the
> Network, and also configure the Microsoft .NET 2.0 Framework Configuration
> by
> adding a new group to the All_Code then this works. Is this correct?

It's one valid way of acquiring a full trust grant.


> I'm new
> to strong names and Microsoft .NET configuration. If I do this, is it
> granting the securities to just my application?

It will grant the elevated permissions to all assemblies signed with your
strong name key unless you also add name and version evidence to the strong
name membership condition for the code group.

> If so then this should be
> acceptable.
>
> Another option would be to simply 'turn off' the thing throwing the
> security
> exception. However its still not clear for me how to do this..its not
> really
> straight forward. I'm on VS 2005 if that helps.

You can't disable the code access security system from within partially
trusted code. Even if you could, you shouldn't since this will leave the
client machines vulnerable to attacks from other assemblies that ought to be
partially trusted.


> Is there anything programmatically i can set in my application which means
> I
> dont have to Configure anything externally?

No.  If you were able to do this, so could a malicious developer.  The
closest you can come at present is deploying as a ClickOnce assembly, where
at least you won't need to modify CAS policy on each client machine.
Author
7 Sep 2006 9:37 AM
David++
Hi Nicole,

Thanks for the reply.

Show quoteHide quote
> > Ok, I've been trying to solve this for the last couple of days now and
> > still
> > no joy. The error that is getting thrown is -
> >
> > Request for the permission of type
> > 'System.Security.Permissions.EnvironmentPermission, mscorlib,
> > Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
> >
> > And if I click details it also says -
> >
> > The Zone of the assembly that failed was:
> > Intranet
> >
> > In the Project properties I have ran the 'Calculate Permissions' and it
> > says
> > that to run the application must be 'Full Trust'. So I have tried
> > deploying
> > as full trust and no joy.
>
> Exactly what happened when you attempted to deploy as a fully trusted
> ClickOnce app?  Were you running from the ClickOnce harness page or were you
> trying to run the executable directly off a network share?  If the former,
> were you prompted to elevate the assembly's permissions?
>

When I built the application i was copying the exe to the network location
along with its config file. I then created a shortcut to the exe and placed
it on my desktop. When I started the app via the shortuct I got the error.

I was not Publishing the app as ClickOnce which is maybe why the FullTrust
settings were not getting added to the exe. However, when I published with
ClickOnce and I run the setup.exe it doesnt prompt me to install the exe at a
certain location, it just seems to run the exe. I guess I would have had to
copy one of the generated application files i.e. either -

MyApp.application
MyApp_1_0_0_0.application

....along with the Folder - MyApp_1_0_0_0 to the network location for it to
work correctly - is this right?

In the end I got around the problem by using the Microsoft Configuration
Tool and creating an MSI Deployment package to install the security settings
on the clients machine. No the ideal solution but did the job at short notice.

Best regards,
David
Author
7 Sep 2006 4:41 PM
Nicole Calinoiu
It sounds like you almost certainly didn't deploy and/or attempt to launch
the ClickOnce application in the intended manner.  For instructions, see
http://msdn2.microsoft.com/en-us/library/142dbbz4.aspx.


Show quoteHide quote
"David++" <Da***@discussions.microsoft.com> wrote in message
news:15CEF970-8C15-4D73-B889-ECFE8C9E483B@microsoft.com...
> Hi Nicole,
>
> Thanks for the reply.
>
>> > Ok, I've been trying to solve this for the last couple of days now and
>> > still
>> > no joy. The error that is getting thrown is -
>> >
>> > Request for the permission of type
>> > 'System.Security.Permissions.EnvironmentPermission, mscorlib,
>> > Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
>> >
>> > And if I click details it also says -
>> >
>> > The Zone of the assembly that failed was:
>> > Intranet
>> >
>> > In the Project properties I have ran the 'Calculate Permissions' and it
>> > says
>> > that to run the application must be 'Full Trust'. So I have tried
>> > deploying
>> > as full trust and no joy.
>>
>> Exactly what happened when you attempted to deploy as a fully trusted
>> ClickOnce app?  Were you running from the ClickOnce harness page or were
>> you
>> trying to run the executable directly off a network share?  If the
>> former,
>> were you prompted to elevate the assembly's permissions?
>>
>
> When I built the application i was copying the exe to the network location
> along with its config file. I then created a shortcut to the exe and
> placed
> it on my desktop. When I started the app via the shortuct I got the error.
>
> I was not Publishing the app as ClickOnce which is maybe why the FullTrust
> settings were not getting added to the exe. However, when I published with
> ClickOnce and I run the setup.exe it doesnt prompt me to install the exe
> at a
> certain location, it just seems to run the exe. I guess I would have had
> to
> copy one of the generated application files i.e. either -
>
> MyApp.application
> MyApp_1_0_0_0.application
>
> ...along with the Folder - MyApp_1_0_0_0 to the network location for it to
> work correctly - is this right?
>
> In the end I got around the problem by using the Microsoft Configuration
> Tool and creating an MSI Deployment package to install the security
> settings
> on the clients machine. No the ideal solution but did the job at short
> notice.
>
> Best regards,
> David