Problem and solution of ASP.net running on virtual host

Source: Internet
Author: User
Tags config execution reflection stack trace
Asp.net| Solution | problem | Virtual Host

Sometimes we write asp.net applications that run on a virtual host. Some virtual hosts may be due to security considerations, the ASP.net permissions to set, can cause our application will not function properly.

Problem phenomenon:
For some reason, asp.net cannot load some DLL files, and the following error prompts: Server error in '/' Application.
---------------------------------------------

Required permissions cannot be acquired.
Description:an unhandled exception occurred during the execution of the current Web request. Please review the "stack Trace for" Information about the error and where it originated in the code.

Exception Details:System.Security.Policy.PolicyException:Required permissions cannot be acquired.

Source Error:

An unhandled exception is generated during the execution of the current Web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[Policyexception:required permissions cannot be acquired.]
System.Security.SecurityManager.ResolvePolicy (Evidence Evidence, PermissionSet reqdpset, PermissionSet optpset, PermissionSet Denypset, permissionset& denied, Boolean checkexecutionpermission) +2738293
System.Security.SecurityManager.ResolvePolicy (Evidence Evidence, PermissionSet reqdpset, PermissionSet optpset, PermissionSet Denypset, permissionset& denied, int32& securityspecialflags, Boolean checkexecutionpermission) +57

[Fileloadexception:could not load file or assembly ' Microsoft.Practices.ObjectBuilder, version=1.0.51205.0, culture= Neutral, Publickeytoken=null ' or one of its dependencies. Failed to grant minimum permission requests. (Exception from hresult:0x80131417)]
System.Reflection.Assembly.nLoad (AssemblyName fileName, String codeBase, Evidence assemblysecurity, Assembly Locationhint, stackcrawlmark& Stackmark, Boolean throwOnFileNotFound, Boolean forintrospection) +0
System.Reflection.Assembly.InternalLoad (AssemblyName assemblyref, Evidence assemblysecurity, stackcrawlmark& Stackmark, Boolean forintrospection) +211
System.Reflection.Assembly.InternalLoad (String assemblystring, Evidence assemblysecurity, stackcrawlmark& Stackmark, Boolean forintrospection) +141
System.Reflection.Assembly.Load (String assemblystring) +25
System.Web.Configuration.CompilationSection.LoadAssemblyHelper (String AssemblyName, Boolean stardirective) +32

Problem Analysis:

According to my observation, the DLL directly generated by the ASP.net application can load normally, and external DLLs called directly by ASP.net can also load normally, but other external DLLs referenced only by external DLLs cannot be loaded. My guess is that because permissions are incomplete, the ASP.net application itself generates DLLs and directly referenced DLLs that gain permissions through inheritance of permissions, while other external DLLs referenced only by external DLLs cannot inherit permissions because of permission limitations, resulting in insufficient permissions.

Problem solving:

By experimenting on my computer, it was speculated that the settings for the root Web.config (the location of C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG on my Computer) were modified on the virtual host.
The default Web.config permission settings section is as follows:

<location allowoverride= "true" >
<system.web>
<securityPolicy>
<trustlevel name= "full" policyfile= "internal"/>
<trustlevel name= "High" policyfile= "Web_hightrust.config"/>
<trustlevel name= "Medium" policyfile= "Web_mediumtrust.config"/>
<trustlevel name= "Low" policyfile= "Web_lowtrust.config"/>
<trustlevel name= "Minimal" policyfile= "Web_minimaltrust.config"/>
</securityPolicy>
<trust level= "full" originurl= "/>
</system.web>
</location>

Speculate on the modified settings on the virtual host:

<location allowoverride= "false" >
<system.web>
<securityPolicy>
<trustlevel name= "full" policyfile= "internal"/>
<trustlevel name= "High" policyfile= "Web_hightrust.config"/>
<trustlevel name= "Medium" policyfile= "Web_mediumtrust.config"/>
<trustlevel name= "Low" policyfile= "Web_lowtrust.config"/>
<trustlevel name= "Minimal" policyfile= "Web_minimaltrust.config"/>
</securityPolicy>
<trust level= "High" originurl= "/>
</system.web>
</location>

He first set the allowoverride to False, which prevents the ability to redefine permissions in the user web.config. He then defines the level of trust as high rather than the default full. As I tested, other external DLLs that are referenced only by external DLLs cannot be loaded as long as the trust level is not full. Therefore, I recommend that technical support set the AllowOverride section to True. So I can reassign the permissions in the web.config.

Example: <trust level= "full" originurl= "/>

Recently has not studied the aps.net, therefore also did not earnestly to look for the deep reason, perhaps my understanding is also wrong. I hope that the master can explain the deep reasons, or correct my mistakes.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.