Understanding LinkDemand Security on a webserver - c#

After deployment an ASP.Net application on a webserver, I get this error message by using code from a external assembly: "LinkDemand The type of the first permission that failed was: System.Security.PermissionSet The Zone of the assembly that failed was: MyComputer the error ".
The assembly is include in the \bin folder and not in the GAC.
I try to know what linkdemand exactly is and why this message will raised. But looking for more information, I don't get exactly the problem.
I try also to add the PermissionSetAttribute on the class where the exception message happens:
[System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.LinkDemand, Name = "FullTrust")]
Then the exception will be raised on another class of the assembly. And so on..
My questions ares:
what exactly is going wrong here? Is it true that what I understand this error message displayed when the Jit cannot check the code security?
Is there maybe a security policy that block this (machine.config) or directly change the security?
Can I set the PermissionAttribute for all classes between a assembly?

Go to administrative tools and local security policy. Whilst, I do not know the exact reason you are getting the error, basically you are trying to execute code that is not allowed in the current security policy. Check your paths and your security policy and the permission requirements of the module. Some paths like desktop will run in reduced security by default.

Related

WebForms application - 'The trust relationship between this workstation and the primary domain failed.'

I have scoured the internet for this particular error and I've found similar ones but nothing that matched my problem. I have a WebForms application that continues to give me the error below.
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: Could not create Windows user token from the credentials specified in the config file. Error from the operating system 'The trust relationship between this workstation and the primary domain failed.
It highlights the line: (I've replaced the username and password with generic text for this post.)
<system.web>
<identity impersonate="true" userName="(Domain\(Username)" password="(Password)"/>
Whenever I change impersonate="false" it just says that LocalHost cannot be found. I'm not sure what the issue is here and I can't seem to get the application to run locally.

System.Security exception on asp.net webpage - c#

I am having an issue where when I run my asp.net website, I get a security exception to do with the trust level in the config file. I have tried adding the following code into the config file in the solution, but no luck;
<securityPolicy>
<trustLevel name="Full" policyFile="internal"/>
</securityPolicy>
Description of the 'Security Exception' -
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 the permission of type 'System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
I am only trying to run this locally from Visual Studio, and it has been working before.
We have recently moved our environments from working in a TS session (where vs2010 is), to having our own virtual machines (where vs2012 is). To get to the VS2010, we have to remote in from our virtual machine, and each time we log in it brings over our documents folder and everything. Could it be to do with this, logging in from somewhere else causes permission issues?
Many thanks.

"The network name cannot be found" exception in ClickOnce deployment?

I'm getting the following exception when I try to install a ClickOnce application:
Below is a summary of the errors, details of these errors are listed later in the log.
* Activation of C:\Users\user\Downloads\appname.application resulted in exception. Following failure messages were detected:
+ Downloading file://192.168.2.9/appdir/appname.application did not succeed.
+ The network name cannot be found.
+ The network name cannot be found.
+ The network name cannot be found.
I haven't been able to figure it out. I've tried looking around on the net and there don't seem to be any resources on the issue. Does anybody know how to resolve this?
This turned out to be a problem with the installation URL in the publish settings. Rather than using a web path, I was using a share for the path. The actual location was set up in IIS, so of course the file could not be found at the share.
Changing the field "Installation Folder URL" from:
\\\server-name\path
to
http://server-name/path
resolved the problem. Silly mistake.
I fixed the issue in this way. Check the Permission in both IIS AND Folder
Give the IIS Full control Permision to Everyone
Share the physical path folder to Everyone
Mostly these kind of error messages are due to wrong connection string that cannot be found over network. Rechecking the Datasource value or server value and and database name in connection string will solve the problem

Solving Assembly not Found | FileNotFoundException | Fusion Log

I am trying to deploy my solution package (wsp) to SharePoint 2007 environment. The WSP contains a feature which loads the feature receiver class to deploy a timer job at run time.
While deploying this WSP, I am consistently getting
Feature
'fb631f6c-2c46-4ab5-b7b3-f3d0c949c5f0'
could not be installed because the
loading of event receiver assembly
"XXX, Version=1.0.0.0,
Culture=neutral,
PublicKeyToken=bad6857072694970"
failed:
System.IO.FileNotFoundException
I have double checked everything (public key token, assembly name etc) is correct. I have deployed many WSP in past and I am confused why this one is failing.
To debug this , I am using Assembly Binding Log Viewer. I have selected "Log in exception text" and given custom log path. Neither I am getting any log messages and the exception text is consistently giving this message:
WRN: Assembly binding logging is
turned OFF. To enable assembly bind
failure logging, set the registry
value
[HKLM\Software\Microsoft\Fusion!EnableLog]
(DWORD) to 1. Note: There is some
performance penalty associated with
assembly bind failure logging. To
turn this feature off, remove the
registry value
[HKLM\Software\Microsoft\Fusion!EnableLog].
Any ideas why this could be happening ? How to enable Assembly Binding Log viewing?
To turn the logging on use Regedit and updated the registry entry in the error message.
It could be that your program requires a dll that is not included in the package.
Sometimes it just needs an IISRESET to realise that the dll is available in the GAC.

Allowing partially trusted callers security exception is been thrown althought running on Full trust mode

While developing using ASP.net 2.0 (C#) and NHibernate 2.1.0
I am getting the error:
System.TypeInitializationException: The type initializer for 'NHibernate.ByteCode.LinFu.ProxyFactory' threw an exception. ---> System.Security.SecurityException: That assembly does not allow partially trusted callers.
This error is been thrown only in the production server (a web hosting company) and in my development environment everything is fine.
I also ran this code below on the production server to see the Code Access Security (CAS) level and got True from:
System.Security.SecurityManager.IsGranted(new AspNetHostingPermission(AspNetHostingPermissionLevel.Unrestricted))
so I can assume I am currently running in a full trusted mode..
After reading some articles about this kind of problem (not specifically for NHibernate)
I understood that I need to add
[assembly: AllowPartiallyTrustedCallers()]
to my AssebmlyInfo.cs file.
My question is:
Is there a way to solve this exception without having to edit the NHibernate.ByteCode.LinFu.dll's AssmeblyInfo.cs ? Is there something that can be configured in the web.config to allow this kind of action?
Thanks,
Tal.
Have you tried the steps called out here?
Using NHibernate in a Medium Trust web environment

Categories

Resources