SecurityException after adding ELMAH to WCF project

I'm having a problem with a WCF (.Net 3.5) site using ELMAH on IIS 7.5. This is the exception message:

System.Security.SecurityException: Request for the permission of type 'System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

To verify that it was the combination of WCF and ELMAH on IIS7.5, I created a new WCF Service project in VS2008 and a new Application under the IIS 7.5 site. I published it and made sure it was okay. Then I added the ELMAH DLL. Still okay. Then added the ELMAH configSection references to Web.config. Still okay. Then I added the ELMAH stuff to httpHandlers and httpModules in system.web (yeah, I know this is not for 7.5). Still okay. Then I added this to handlers and modules in system.webServer:

<handlers>
    :
  <add name="Elmah" verb="POST,GET,HEAD" 
       path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />

<modules>
    :
  <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
  <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
  <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />

And then I got the security exception. I've made no other config changes.

Everything works using the VS dev webserver. The development machine is 2008 R2 x64 with VS 2008 SP1 installed. The WCF service is built for x86 (because the original project was). ELMAH is the .Net 3.5 x86 version. The IIS7.5 app pool is set to allow 32-bit.

Any idea what I need to do to get this working?

Answers


In my case, I had to set the "load User Profile=True" in app pool to make it work.

Steps:

From application pools list, Go to Advanced Settings, Process Model section and set "Load User Profile" to "True".


You will have to go to Add managed handler in the IIS Manager for your virtual web directory.

  • Request Path will be : elmah.axd
  • Type will be: Elmah.ErrorLogPageFactory, Elmah
  • Name: Anything you want it to be identified with.

Note: This settings will be removed every time you publish changes from Visual Studio. So you will have to add it again.


Need Your Help

Webbrowser height calculation top margin falsely taken into account?

html css internet-explorer google-chrome firefox

In one of our projects we noticed the following strange calculation in all major browsers (Firefox 22.0, Chrome 28.0.1500.72 m, IE 10.0.9200.16521)

server certificate is not configured properly with HTTP.SYS in the HTTPS case

c# wcf ssl

I need to use a third party WCF service. I have configured the required certificate on my certificate store however I am getting following exception when calling the WCF service.