I've implemented this code in my HttpModule and found that Cassini (the visual studio integrated web server) performance seems to degrade to crippling levels. I've also tested in IIS Express and things work fine there. The cassini web server exhibits this
behavior when the webapp is configured to connect to the out-of-proc session server, and using the session state enforcer code demonstrated in this thread.
The symptoms:
Long page loads - Page loads go from 12seconds to 2+ minutes.
file not found - It seems that some requests for files that don't exist degrade even worse with what appears to be a deadlock or infinite loop that I have never seen complete. The pages never finish loading (firebug shows some missing images that just spin
forever and keep the page and other resources from finishing loading).
Environment:
Tested in windows 7 64bit and 32 bit
Visual Studio 2010
ASP.NET 4.0
(not sure if i anything else would be relevant)
Steps To Reproduce:
Create a new 'ASP.NET Empty Web Application' named CassiniDeadlock404Test make sure it's going to be hosted by cassini via project properties).
Create new class file DeadlockModule.cs and add code:
using System;
using System.Web;
using System.Web.SessionState;
namespace CassiniDeadlock404Test {
public class DeadlockModule : IHttpModule
{
public void Dispose() {
throw new NotImplementedException();
}
public virtual void Init(HttpApplication context) {
context.PostAcquireRequestState += this.PostMapRequest;
context.PostMapRequestHandler += this.PostAcquireRequest;
}
void PostMapRequest(object source, EventArgs e) {
HttpApplication app = (HttpApplication)source;
if (app.Context.Handler is IReadOnlySessionState ||
app.Context.Handler is IRequiresSessionState) {
return;
}
app.Context.Handler = new SessionStateEnforcer(app.Context.Handler);
}
void PostAcquireRequest(object source, EventArgs e) {
HttpApplication app = (HttpApplication)source;
SessionStateEnforcer handler = HttpContext.Current.Handler as SessionStateEnforcer;
if (handler != null) {
HttpContext.Current.Handler = handler._original;
}
}
public class SessionStateEnforcer: IHttpHandler, IRequireSessionState
{
internal IHttpHandler _original = null;
public SessionStateEnforcer(IHttpHandler original) {
this._original = original;
}
public void ProcessRequest(HttpContext context) {
throw new InvalidOperationExcpetion("iop");
}
public bool IsReusable { get { return false; } }
}
}
}
Create new page index.aspx and add code:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="CassiniDeadlock404Test.index" %>
<!DOCTYPE html PUBLIC "~//W3C/DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
This is some text before the missing image
<img src="/data/images/404-for-this-image.jpg" />
This is some text after the missing image
</div>
</body>
</html>
Run the web server and hit index.aspx page. It takes over a minute to load. Disable the Outofproc session state server in the config file. It will take < 1 second to load. Disable the session state enforcer module code and the page will take < 1 second to
load.
hannasm
Member
2 Points
2 Posts
SessionState in HttpModule problem (2.0)
Feb 04, 2012 09:03 PM|LINK
Original Thread: http://forums.asp.net/t/1098574.aspx/1?SessionState+in+HttpModule+problem+2+0+
I've implemented this code in my HttpModule and found that Cassini (the visual studio integrated web server) performance seems to degrade to crippling levels. I've also tested in IIS Express and things work fine there. The cassini web server exhibits this behavior when the webapp is configured to connect to the out-of-proc session server, and using the session state enforcer code demonstrated in this thread.
The symptoms:
Long page loads - Page loads go from 12seconds to 2+ minutes.
file not found - It seems that some requests for files that don't exist degrade even worse with what appears to be a deadlock or infinite loop that I have never seen complete. The pages never finish loading (firebug shows some missing images that just spin forever and keep the page and other resources from finishing loading).
Environment:
Tested in windows 7 64bit and 32 bit
Visual Studio 2010
ASP.NET 4.0
(not sure if i anything else would be relevant)
Steps To Reproduce:
Create a new 'ASP.NET Empty Web Application' named CassiniDeadlock404Test make sure it's going to be hosted by cassini via project properties).
Open web.config and set to:
<?xml version="1.0"?> <configuration> <system.web> <sessionState mode="StateServer" stateConnectionString="tcpip=localhost:42424" cookieless="false" timeout="60" /> <compilation debug="true" targetFramework="4.0" /> <httpModules> <add name="DeadlockModule" type="CassiniDeadlock404Test.DeadlockModule" /> </httpModules> </system.web> </configuration>Create new class file DeadlockModule.cs and add code:
using System; using System.Web; using System.Web.SessionState; namespace CassiniDeadlock404Test { public class DeadlockModule : IHttpModule { public void Dispose() { throw new NotImplementedException(); } public virtual void Init(HttpApplication context) { context.PostAcquireRequestState += this.PostMapRequest; context.PostMapRequestHandler += this.PostAcquireRequest; } void PostMapRequest(object source, EventArgs e) { HttpApplication app = (HttpApplication)source; if (app.Context.Handler is IReadOnlySessionState || app.Context.Handler is IRequiresSessionState) { return; } app.Context.Handler = new SessionStateEnforcer(app.Context.Handler); } void PostAcquireRequest(object source, EventArgs e) { HttpApplication app = (HttpApplication)source; SessionStateEnforcer handler = HttpContext.Current.Handler as SessionStateEnforcer; if (handler != null) { HttpContext.Current.Handler = handler._original; } } public class SessionStateEnforcer: IHttpHandler, IRequireSessionState { internal IHttpHandler _original = null; public SessionStateEnforcer(IHttpHandler original) { this._original = original; } public void ProcessRequest(HttpContext context) { throw new InvalidOperationExcpetion("iop"); } public bool IsReusable { get { return false; } } } } }Create new page index.aspx and add code:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="CassiniDeadlock404Test.index" %> <!DOCTYPE html PUBLIC "~//W3C/DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> This is some text before the missing image <img src="/data/images/404-for-this-image.jpg" /> This is some text after the missing image </div> </body> </html>Run the web server and hit index.aspx page. It takes over a minute to load. Disable the Outofproc session state server in the config file. It will take < 1 second to load. Disable the session state enforcer module code and the page will take < 1 second to load.