Please note that depending on the version of ASP.NET that you have set for your website and the pipeline type you may need to Change ASP.NET to Full Trust in order for the above code to function correctly.