View Single Post
  #1 (permalink)  
Old 06-10-2007, 05:21 PM
Somnath M
Posts: n/a
[SOLVED] HTTPModule : ASP.NET 2.0?

Suppose I have site xyz.com. Site has a page called show_user.aspx where I need to access the Session variables.
But this show_user.aspx page will not be called directly Instead , when user type xyz.com/somnath …it will interpret “somnath” as a user name and internally call page show_user.aspx?user=somnath.
I have created a HTTP module URLCheckingModule for URL checking.
This is settings in my web.config file

<httpModules>
<add name="Session" type="System.Web.SessionState.SessionStateModule"/>
<add name="URLChecking" type="UserProfileModule"/>
</httpModules>
<pages enableSessionState="true" />
</system.web>
</configuration>
my Class code ...


public class UserProfileModule : IHttpModule
{
public void Init(HttpApplication app)
{
app.PreRequestHandlerExecute += new EventHandler(this.OnPreRequest);
}
private void OnPreRequest(object sender, EventArgs e)
{

HttpContext context = HttpContext.Current;
HttpRequest request = context.Request;
string FilePath = request.FilePath;
string ext = Path.GetExtension(FilePath);

if (string.IsNullOrEmpty(ext) && !FilePath.EndsWith("/"))
{
// suppose URL is http://xyz.com/somnath/
// and empty Extension
string q = request.QueryString.ToString();
string path = request.FilePath + "/" + (string.IsNullOrEmpty(q) ? "" : q);
context.Server.Transfer("show_user.aspx" );
}
else
{
if (FilePath.EndsWith("/"))
{
string dPath;
dPath = context.Server.MapPath(FilePath);
if (Directory.Exists(dPath) == false)
{
FilePath = FilePath.Remove(FilePath.Length - 1, 1
FilePath = FilePath.Remove(FilePath.Length - 1, 1);
context.Response.Redirect(FilePath);
}
}
}
}

public void Dispose()
{
}
}
Now,

If in the show_user.aspx, works well, if I don’t have any session related calls, but gives error if I want to work with Session.

Response.Write(Session["somnath"]);
// note I have set the Session in the default page.
Server Error in '/WebTest' Application.
________________________________________
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.
Note:
1.I have already set the Session module in Web.config.
2.To ensure that , Sessionstate should be available I have added Module at “PreRequestHandlerExecute” ,

AS per MSDN documentation Session state is available in this event.


I am stuck on this problem. Logically there is no reason to code to not work, as all steps are followed.
Please help me for this problem.
I have added IReadOnlySessionState , but sill same problem. Session is null.

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!