ASP.NET Trust Level

Friday, 27 March 2009 13:58 by scngan

In order to modify the trust level, you need to make sure you can access to c:\windows folder as the setting is reside there.

Error message that going to appear if regarding trust level :

Server Error in '/' Application. 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 failed.


Path that contain the setting :
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\Web.config

DEFAULT setting:
<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>

Add the following code before the above code to execlude your site to run in any other trust:

<location path="Your IIS hostheader name" allowOverride="true">
    <system.web>
        <trust level="Full or Medium or Low" originUrl="" />
    </system.web>
</location>

Your finalized web.config should be something like this:

<location path="Your IIS Host Header" allowOverride="true">
    <system.web>
        <trust level="Full" originUrl="" />
    </system.web>
</location>

<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="Medium" originUrl="" />
    </system.web>
</location>

*Take note that the above final web.config trust level has been reduce to Medium for the server. And your site is running in full trust.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:   ,
Categories:   Technical Stuff
Actions:   | E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed
Comments are closed