Blog HowTo

When you want to blog, here is how to do it. Featuring technical solutions.

Customizing Trust Level Policy for Subtext

Predefined trust level policies are Extensible Markup Language (XML) files that give details on the various security settings. To run Subtext v1.9 at medium trust, you can create a customized policy by modifying the existing predefined medium trust policy to include permissions for webservices. Because there is a risk associated with enabling WebPermission, it is not enabled by default. 
With this approach, you do the following:

  • Copy the existing medium trust-level policy file to create your custom policy file.
  • Add the required permissions to the custom policy file.
  • Configure the machine-level Web.config to use the custom policy.

The following steps provide the details for creating a customized medium trust level policy that modifies the default web services permissions.
        To create the custom trust level configuration file and add a new permission:

  1. Copy the Medium trust policy file, web_MediumTrust.config, to create a new policy file in the same directory (%windir%\Microsoft.NET\Framework\{version}\CONFIG\). Give it a name that indicates that it is a variation of Medium trust. For instance, it could be named web_MediumTrustWithWebServices.config. (These steps assume 'web_MediumTrustWithWebServices.config' is the name you will be using. If you use a different name, don’t forget to change it throughout these steps.)
  2. Modify the default Web.config file in the %windir%\Microsoft.NET\Framework\{version}\CONFIG\ directory to add the custom trust level that references the custom trust configuration file you have created (i.e., the file web_MediumTrustWithWebServices.config). To do this, add a new element to the section of the Web.config file to define a new level called "MediumWithWebServices" and to associate it with the custom policy file, as shown here. (MediumWithWebServices is a suggested name. You can pick another name, but all these steps assume the name used is MediumWithWebServices.)

       
         
          
          
          
          
          
          
         
         
        
      

    These changes apply to the root Web.config file in the framework CONFIG folder. This applies defaults to all Web pplications on the current server. However, so far, you are only making this new policy available as an option. No apps will be affected at this point. In the next step Subtext will be modified to use this new policy file.

  3. Open the web.config file in your Subtext.Web folder and change the trust element as follows:

       
           

  4. When you save the modified web.config file, your blog application will restart. Make sure it runs correctly. So far you have not changed any policies! You have merely established the new policy file that you will modify in a later step.
  5. When you are satisfied that your blog is still operating, move on to the next step, which actually changes the policy.
  6. Open the new web_MediumTrustWithWebServices.config file in Notepad.
  7. Change the web services permission in the custom policy (i.e., the file web_MediumTrustWithWebServices.config) by following these two steps:
    1. First, find the WebPermission in the web_CustomTrust.config file, as shown in the following example.
      ...
          
                        version="1"
                              
                                    
                              

      ...

    2. Then edit the WebPermission so that the ConnectAccess element is removed and Unrestricted is set to true, as shown in the following example.
      ...
          
                        version="1" 
                        Unrestricted="true"/>
      ...
  8. When you restart your blog application, the new policy will take effect.