.NET Security Exception Error

I’ve been meaning to write a post on this for ages but I’ve always forgotten to take a screenshot until now. If you ever get this error thrown from your .NET 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


This always means that you need to set your trust level to “Full” in your web.config file in order to correct the problem.  I’ve included the correct XML markup that you need to add/modify in your web.config file below:

< ?xml version="1.0" encoding="UTF-8"?>
  <system .web>
    <trust level="Full"></trust>

How to Properly Configure Password Protection using IIS Manager

I wrote this article because there seems to be some conflicting information on the Internet, but there is a simple way to password protect a directory in IIS with IIS Manager.

  1. First, connect to your site using IIS Manager.
  2. Next, highlight the root folder or the sub-folder you want to protect and then double click on the Authorization Rules module.


3. Now, highlight the Allow All Users rule and click on the Remove link.


4. Click on the Add Allow Rule… link which will bring up the window below.


5. Select the Specified users: option, enter a Windows/FTP username which has access to the site, and click on the OK button.

Now, when you enter the URL that points to the folder, you will be prompted to enter your Windows credentials to gain access.  If you prefer, you can create a web.config file with the following markup (or add it to an existing one) and place it the directory you want to protect.

< ?xml version="1.0" encoding="UTF-8"?>
    <system .webServer>
                <remove users="*" roles="" verbs=""></remove>
                <add accessType="Allow" users="WindowsUsername"></add>

SQL Error involving Auto Close

This was a solution I discovered years ago when troubleshooting a customer’s database problem.  The error thrown was:

The log for database ‘database_name’ is not available. Check the event log for related error messages. Resolve any errors and restart the database.

It was caused by the Auto Close database property being set to true.  To rectify the issue, you will need to bring the database offline, bring it back online again, and then set the Auto Close property to false.