473,386 Members | 1,733 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Security Exception

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);

IPermission permission = null;
foreach(string strGroup in groups)
{
string strDomainAndGroup = strGroup;
if(strGroup.IndexOf ('\\') == -1)
{
strDomainAndGroup = Environment.MachineName + "\\" + strGroup;
}

if(permission == null)
{
permission = new PrincipalPermission(null, strDomainAndGroup);
}
else
{
permission = permission.Union(new PrincipalPermission(null,
strDomainAndGroup));
}
}

if(permission != null)
{
permission.Demand();

// Revert to self, so that all actions now happen as the
// process user, not as the impersonated user.
Win32.AdvApi.RevertToSelf();

}
}

but i get the following error when i hit the "permission.Demand();" line

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: System.Security.SecurityException: Request for principal
permission failed.

I know it says i must change the application's trust level. but i dont know
how to do this? someone have an example? or a solution to my problem even?
it would be much appreciated... thanks.

Jason
Nov 19 '05 #1
1 2627
"Jason" <c_*******@mighty.co.za> wrote in
news:Og**************@tk2msftngp13.phx.gbl:
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);

IPermission permission = null;
foreach(string strGroup in groups)
{
string strDomainAndGroup = strGroup;
if(strGroup.IndexOf ('\\') == -1)
{
strDomainAndGroup = Environment.MachineName + "\\" +
strGroup;
}

if(permission == null)
{
permission = new PrincipalPermission(null,
strDomainAndGroup);
}
else
{
permission = permission.Union(new PrincipalPermission(null,
strDomainAndGroup));
}
}

if(permission != null)
{
permission.Demand();

// Revert to self, so that all actions now happen as the
// process user, not as the impersonated user.
Win32.AdvApi.RevertToSelf();

}
}

but i get the following error when i hit the
"permission.Demand();" line

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: System.Security.SecurityException: Request
for principal permission failed.

I know it says i must change the application's trust level. but
i dont know how to do this? someone have an example? or a
solution to my problem even? it would be much appreciated...
thanks.


Jason,

I think you may have the wrong impression as to what the
Demand() method does.

Demand() is not a "demand" in the sense that your code is
demanding to be given a permission. There is no way for
code to grant itself more permissions that it was granted
by the security policies set by the administrator.
Demand() is "demanding" that .Net verify a certain state is
true. In this case, the state to be verified is whether
or not the role and ID of the PrincipalPermission match
the role and ID of the current thread's principal.
You are getting an exception because one or more of
your groups is not in the list of roles of the current
thread's principal.

http://msdn.microsoft.com/library/de...classtopic.asp

or

http://tinyurl.com/7xpds

You could change your void method Demand to a boolean method
called IsAuthenticated. Wrap the permission.Demand() call
in a try/catch block, and return false from the catch block.
Return true if no exceptions occur.

You also appear to be doing some kind of identity impersonation
through the Windows API. (Note that Demand() does not have anything
to do with impersonation). Managed wrappers for this functionality
are provided in the .Net framework.

http://msdn.microsoft.com/library/de...etdataflow.asp

or

http://tinyurl.com/4pu4a

There are also many messages in Google Groups and pages in the
regular Google search engine relating to ASP.Net impersonation.
--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 19 '05 #2

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

Similar topics

0
by: James B | last post by:
OMA (Outlook Mobile Access) under Exchange is giving me a System.Security.SecurityException error. From what I gather this is a problem with the security level under which the OMA application is...
0
by: James B | last post by:
OMA (Outlook Mobile Access) under Exchange is giving me a System.Security.SecurityException error. From what I gather this is a problem with the security level under which the OMA application is...
3
by: Chua Wen Ching | last post by:
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;
19
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...
0
by: Carl Gilbert | last post by:
Hi I am trying to get an online gallery to work (www.ngallery.org). I have managed to get it all working on my local host but I can not get it to work on my web space. The site can be found...
5
by: CyberLotus | last post by:
Hi, I've created a web application and through this I want to import Excel data to database. Following is the code that I've written, ...
2
by: KaNos | last post by:
Hello world, I've made a webservice (c# v2) to install in a server IIS 6 on a Windows 2000 last SP. We can use the webservice in local, throw the pages wich present the methods, with a windows...
3
by: Mike | last post by:
Hi I have problem as folow: Caught Exception: System.Configuration.ConfigurationErrorsException: An error occurred loading a configuration file: Request for the permission of type...
8
by: =?Utf-8?B?TWFuanJlZSBHYXJn?= | last post by:
Hi, I created a web service and hosted it in Windows Services. It is working fine. Now I am trying to implement the X509 certificates for message layer security. But it is throwing the following...
5
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...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.