0

I am getting error when I launch my application.

An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode.

I have created an HTTP module which read information from the request header and writes data into cookies. Here is the code.

namespace My.Web
{
    public class UserIdModule : IHttpModule
    {
        private HttpApplication httpApp;

        public void Init(HttpApplication application)
        {
            application.BeginRequest += (new EventHandler(this.Application_BeginRequest));
        }


        private void Application_BeginRequest(Object source, EventArgs e)
        {
            // Create HttpApplication and HttpContext objects to access
            // request and response properties.
            HttpApplication application = (HttpApplication)source;
            HttpContext context = application.Context;

            //Read header
            string userId = context.Request.Headers["user_id"];

            if (string.IsNullOrEmpty(userId))
            {
                userId = "guest";
            }

            //Create and write cookie
            HttpCookie userCookie = new HttpCookie("userId", userId);
            userCookie.Expires = DateTime.Now.AddYears(5);  
            context.Response.Cookies.Add(userCookie);
        }

        public void Dispose() { }
    }
}

In my web.config

<configuration>
  <system.webServer>
    <staticContent>
      <mimeMap fileExtension=".*" mimeType="application/octet-stream" />
    </staticContent>
    <!-- To register the module for IIS 6.0 and IIS 7.0 running in Classic mode -->
    <modules>
      <add name="UserIdModule" type="UserIdModule"/>
    </modules>
  </system.webServer>
  <system.web>
    <compilation targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
    <!-- To register the module for IIS 7.0 running in Integrated mode -->
    <httpModules>
      <add name="UserIdModule" type="UserIdModule"/>
    </httpModules>
  </system.web>
</configuration>

This is the screenshot of the error: enter image description here

SharpCoder
  • 18,279
  • 43
  • 153
  • 249
  • Check these http://stackoverflow.com/questions/7370513/http-error-500-22-internal-server-error-an-asp-net-setting-has-been-detected, http://stackoverflow.com/questions/4209999/an-asp-net-setting-has-been-detected-that-does-not-apply-in-integrated-managed-p – malkam Sep 05 '14 at 13:48

2 Answers2

0

I think you may have the Integrated and Classic modes reversed - at least it appears that way from your comments in the config file.

system.web is for the older Classic mode and system.webserver is for Integrated mode. See the following SO answer for reference.

If you have some configuration settings in one that normally belongs to the other I could see you getting this error.

Community
  • 1
  • 1
JasonCoder
  • 1,126
  • 2
  • 12
  • 24
0

Is it IIS 7.5 can you try

<system.webServer>
    <modules>
       <add name="UserIdModule"  type="My.Web.UserIdModule"/>
    </modules>
</system.webServer>