hello
when i use HTTP module for URL rewriting , i get this error:
Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive. Please also make sure that System.Web.SessionStateModule or a custom session state module is included in the <configuration>\<system.web>\<httpmodules> section in the application configuration.
My URL rewriting code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
public class URLRewriter : IHttpModule
{
#region IHttpModule Members
public void Dispose()
{
}
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(context_BeginRequest);
}
void context_BeginRequest(object sender, EventArgs e)
{
HttpApplication httpApplication = sender as HttpApplication;
if (httpApplication != null)
{
string requestPath = httpApplication.Context.Request.Path;
string translationPath = "";
switch (requestPath.ToLower())
{
case "/laptops/dell/":
translationPath = "/showitem.aspx?itemid=7";
break;
case "/laptops/hp/":
translationPath = "/showitem.aspx?itemid=8";
break;
default:
translationPath = requestPath.ToLower();
break;
}
httpApplication.Context.Server.Transfer(translationPath);
}
}
#endregion
}
My Config Code :
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http:
-->
<configuration>
<system.webServer>
<modules>
<add name="URLRewriter" type="URLRewriter"/>
</modules>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>
<connectionStrings>
<add name="conn" connectionString="Data Source=.;Initial Catalog=CMS;User ID=sa;Password=123456" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
</assemblies>
</compilation>
<httpRuntime targetFramework="4.0"/>
<pages enableSessionState="true" />
<sessionState mode="StateServer"></sessionState>
<httpModules >
<add name="URLRewriter" type="URLRewriter"/>
<add type="System.Web.SessionState.SessionStateModule" name="Session" />
</httpModules>
</system.web>
<appSettings>
<add key="webpages:Enabled" value="true"/>
</appSettings>
</configuration>
Please Help Me . Thank You.