473,609 Members | 1,818 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Apply security permission in class library, fail to call it out!

Hi there,

I had applied this security permissions in my class library based on fxcop
standards.

Before namespace:

using System.Runtime. InteropServices ;
using System.Security .Permissions;

[assembly:Isolat edStorageFilePe rmission(Securi tyAction.Reques tMinimum,
UserQuota=10485 76)]
[assembly:Securi tyPermission(Se curityAction.Re questRefuse,
UnmanagedCode=t rue)]
[assembly:FileIO Permission(Secu rityAction.Requ estOptional, Unrestricted=tr ue)]

In AssemblyInfo.cs

[assembly: AssemblyKeyFile ("../../snkey.snk")]

But when my windows app try to all the function during run time, it just
fails.

The errors:

An unhandled exception of type 'System.Securit y.SecurityExcep tion' occured
in Tester.exe

Any tips?

Thanks.
--
Regards,
Chua Wen Ching :)
Nov 16 '05 #1
3 2753
Hi there,

if the exception is being thrown right after you start the app, there should
be a problem with the requested permissions (The RequestMinimum for example
or some more like it in the app).

Before the CLR starts the execution of the assembly, it will check if all of
the requested permissions are being granted. That means that based on the
evidences for the assembly's origin (zone it is being started from, strong
name, digital signature, etc.) it will be assigned to a predefined code
group.
If at that point, the CLR can't apply the securty request, an exception will
be trown(which might be a SecurityExcepti on or PolicyException - depending
on the case).

Otherwise, if the exception is being thrown after the app starts, you should
try to find where the exception is being trowned - there should be a problem
with some resource (something else than those with RequestMinimum or an
action performed to a resource being explicitly refused or optional - like
the FileIO or the UnmanagedCode) not being allowed by the CLR's Security
system to your app. The problem might be the restricted user's account under
you're trying to start the app or something else - like starting it from a
network location (which is not being detected as local intranet) - in this
case the CAS (code access security) just restricts the permissions to the
app.

Hope that helps,
Branimir

--
Branimir Giurov
MCSD.NET, MCDBA
www.sofiadev.org

"Chua Wen Ching" <ch************ @nospam.hotmail .com> wrote in message
news:E7******** *************** ***********@mic rosoft.com...
Hi there,

I had applied this security permissions in my class library based on fxcop
standards.

Before namespace:

using System.Runtime. InteropServices ;
using System.Security .Permissions;

[assembly:Isolat edStorageFilePe rmission(Securi tyAction.Reques tMinimum,
UserQuota=10485 76)]
[assembly:Securi tyPermission(Se curityAction.Re questRefuse,
UnmanagedCode=t rue)]
[assembly:FileIO Permission(Secu rityAction.Requ estOptional, Unrestricted=tr ue)]
In AssemblyInfo.cs

[assembly: AssemblyKeyFile ("../../snkey.snk")]

But when my windows app try to all the function during run time, it just
fails.

The errors:

An unhandled exception of type 'System.Securit y.SecurityExcep tion' occured
in Tester.exe

Any tips?

Thanks.
--
Regards,
Chua Wen Ching :)

Nov 16 '05 #2
I had a tester app with a button. Inside the button click function, it will
call the class library with security permission.

It means, when i run the app no problem, just when i click on the button, i
receive the security problem.

Thanks for the previous tip. Do i need to do anything extra on the tester
app? Like coding attributes or doing something to allow me? Or is more to
permission on windows side?

Thanks again.

"Branimir Giurov" wrote:
Hi there,

if the exception is being thrown right after you start the app, there should
be a problem with the requested permissions (The RequestMinimum for example
or some more like it in the app).

Before the CLR starts the execution of the assembly, it will check if all of
the requested permissions are being granted. That means that based on the
evidences for the assembly's origin (zone it is being started from, strong
name, digital signature, etc.) it will be assigned to a predefined code
group.
If at that point, the CLR can't apply the securty request, an exception will
be trown(which might be a SecurityExcepti on or PolicyException - depending
on the case).

Otherwise, if the exception is being thrown after the app starts, you should
try to find where the exception is being trowned - there should be a problem
with some resource (something else than those with RequestMinimum or an
action performed to a resource being explicitly refused or optional - like
the FileIO or the UnmanagedCode) not being allowed by the CLR's Security
system to your app. The problem might be the restricted user's account under
you're trying to start the app or something else - like starting it from a
network location (which is not being detected as local intranet) - in this
case the CAS (code access security) just restricts the permissions to the
app.

Hope that helps,
Branimir

--
Branimir Giurov
MCSD.NET, MCDBA
www.sofiadev.org

"Chua Wen Ching" <ch************ @nospam.hotmail .com> wrote in message
news:E7******** *************** ***********@mic rosoft.com...
Hi there,

I had applied this security permissions in my class library based on fxcop
standards.

Before namespace:

using System.Runtime. InteropServices ;
using System.Security .Permissions;

[assembly:Isolat edStorageFilePe rmission(Securi tyAction.Reques tMinimum,
UserQuota=10485 76)]
[assembly:Securi tyPermission(Se curityAction.Re questRefuse,
UnmanagedCode=t rue)]
[assembly:FileIO Permission(Secu rityAction.Requ estOptional,

Unrestricted=tr ue)]

In AssemblyInfo.cs

[assembly: AssemblyKeyFile ("../../snkey.snk")]

But when my windows app try to all the function during run time, it just
fails.

The errors:

An unhandled exception of type 'System.Securit y.SecurityExcep tion' occured
in Tester.exe

Any tips?

Thanks.
--
Regards,
Chua Wen Ching :)


Nov 16 '05 #3
It depends -

if there is a permission denied from the OS (like file permission) it should
throw an exception as well. You can do something else - try to do a security
demand in the class library before accessing a resource. Before the demand,
write into the debuger or the trace, then do the same after the deman. The
security demand will wall the call stack and make sure that the callers have
the the same permissions as well as the one you're asking for. For example:

Trace.WriteLine ("before demand permission to ...");
FileIOPermissio n fp = new FileIOPermissio n(FileIOPermiss ionAccess.Read,
"c:\\test.txt") ;
fp.Demand();
Trace.WriteLine ("after demand permission to ...");

You should do that if you can't debug the source with VS. By doing this, you
can intercept where the exception comes from. The other possible solution is
to compile in a Debug mode and catch the permission at app level. Then log
the stack trace and the message. By looking at the stack trace, you'll see
in which method the exception was thrown originally.

Let me know how it goes. :)

Branimir

--
Branimir Giurov
MCSD.NET, MCDBA
www.sofiadev.org

"Chua Wen Ching" <ch************ @nospam.hotmail .com> wrote in message
news:CC******** *************** ***********@mic rosoft.com...
I had a tester app with a button. Inside the button click function, it will call the class library with security permission.

It means, when i run the app no problem, just when i click on the button, i receive the security problem.

Thanks for the previous tip. Do i need to do anything extra on the tester
app? Like coding attributes or doing something to allow me? Or is more to
permission on windows side?

Thanks again.

"Branimir Giurov" wrote:
Hi there,

if the exception is being thrown right after you start the app, there should be a problem with the requested permissions (The RequestMinimum for example or some more like it in the app).

Before the CLR starts the execution of the assembly, it will check if all of the requested permissions are being granted. That means that based on the evidences for the assembly's origin (zone it is being started from, strong name, digital signature, etc.) it will be assigned to a predefined code
group.
If at that point, the CLR can't apply the securty request, an exception will be trown(which might be a SecurityExcepti on or PolicyException - depending on the case).

Otherwise, if the exception is being thrown after the app starts, you should try to find where the exception is being trowned - there should be a problem with some resource (something else than those with RequestMinimum or an
action performed to a resource being explicitly refused or optional - like the FileIO or the UnmanagedCode) not being allowed by the CLR's Security
system to your app. The problem might be the restricted user's account under you're trying to start the app or something else - like starting it from a network location (which is not being detected as local intranet) - in this case the CAS (code access security) just restricts the permissions to the app.

Hope that helps,
Branimir

--
Branimir Giurov
MCSD.NET, MCDBA
www.sofiadev.org

"Chua Wen Ching" <ch************ @nospam.hotmail .com> wrote in message
news:E7******** *************** ***********@mic rosoft.com...
Hi there,

I had applied this security permissions in my class library based on fxcop standards.

Before namespace:

using System.Runtime. InteropServices ;
using System.Security .Permissions;

[assembly:Isolat edStorageFilePe rmission(Securi tyAction.Reques tMinimum,
UserQuota=10485 76)]
[assembly:Securi tyPermission(Se curityAction.Re questRefuse,
UnmanagedCode=t rue)]
[assembly:FileIO Permission(Secu rityAction.Requ estOptional,

Unrestricted=tr ue)]

In AssemblyInfo.cs

[assembly: AssemblyKeyFile ("../../snkey.snk")]

But when my windows app try to all the function during run time, it just fails.

The errors:

An unhandled exception of type 'System.Securit y.SecurityExcep tion' occured in Tester.exe

Any tips?

Thanks.
--
Regards,
Chua Wen Ching :)


Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2495
by: Olaf Baeyens | last post by:
Can someone out there point me to a URL or other reference how to use these security stuff in .NET? I know everything can be found online on the msdn but since I am new to this security stuff, I have a very hard time to find the correct page in the zillions of abstract pages talking about this topic. One of the problems is this: I can find information about FileIOPermission here:
3
2346
by: craig | last post by:
I am working on my first .NET development project that involves custom role-based security per the project requirements. This lead to a general design issue this week that really caused us some concern. I have described the situation below because we are very curious to see what other, more experienced, developers might suggest. The specific classes and fields are used just to illustrate the concepts. Our application uses role-based...
3
2404
by: James Radke | last post by:
Hello, I have an asp.net application (using vb.net codebehind), that is calling some older c++ dlls. These dlls require the use of the c++ Runtime which is in the windows/System32 directories. What is the best way to get access to these directories for the web application? Add the security for IUSR_<system name> to the System32 directory? Is there a better method?
16
2098
by: Marina | last post by:
Hi, I am trying to find the minimum security settings to allow a windows control embedded in IE have full trust. If I give the entire Intranet zone full trust, this works. However, this is very broad and gives the entire zone high privleges. I tried giving just the assembly full trust (using the full URL for the DLL), but this doesn't seem to work.
29
15516
by: Patrick | last post by:
I have the following code, which regardless which works fine and logs to the EventViewer regardless of whether <processModel/> section of machine.config is set to username="SYSTEM" or "machine" ---Start of test.aspx---- <%@ Page language="C#" AutoEventWireup="false" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <HTML> <HEAD>
3
415
by: Earl Teigrob | last post by:
Background: When I create a ASP.NET control (User or custom), it often requires security to be set for certain functionality with the control. For example, a news release user control that is comprised of a DataGrid may have separate permissions for adding, deleting and updating a news item. Problem Up until now, I have been implementing security directly inside the control. I will test directly against the security model to see if...
1
2654
by: Jason | last post by:
Hi I have a ASP.NET application where i would like to authenticate the connecting users according to the Local Users and Groups on the web server. I have the following code in the ASP.NET project. private static void Demand(string groups) { WindowsIdentity processIdentity = WindowsIdentity.GetCurrent(); Console.WriteLine(processIdentity.Name);
19
3205
by: Diego F. | last post by:
I think I'll never come across that error. It happens when running code from a DLL that tries to write to disk. I added permissions in the project folder, the wwwroot and in IIS to NETWORK_SERVICE and Everyone, with Full Control to see if it's a permissions problem. The project is hosted in a Windows 2003 Server and developed from PCs in a domain, developing with Visual Studio 2005 Beta 1. -- Regards,
5
8299
by: Henry Stock | last post by:
I am trying to understand the following error: Any thing you can tell me about this is appreciated. Security Exception Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. Exception Details: for the permission of type
0
8133
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8224
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7013
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5517
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4026
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4091
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2535
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 we have to send another system
1
1676
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1393
bsmnconsultancy
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.