The ProgrammersTalk Community
Forum Register Search Today's Posts Mark Forums Read
Register

Go Back   The ProgrammersTalk Community > Web Programming > ASP / ASP.NET


Welcome to the The ProgrammersTalk Community forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.
Tags:

Closed Thread
 
LinkBack Thread Tools    Display Modes   
  #1 (permalink)  
Old 06-10-2007, 04: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!
  #2 (permalink)  
Old 06-10-2007, 04:21 PM
Rex M Rex M is offline
Novice
Join Date: Jun 2007
Posts: 8
iTrader: (0)
Rex M is on a distinguished road
In order for your module to work, make sure IIS is configured to pass all requests (not just .aspx requests) to the .NET framework.

To access Session from an HTTPModule, you must add the IReadOnlySessionState or the IRequiresSessionState (readonly is better for performance if you don't need to write to the session).

__________________
Powered by Yahoo! Answers
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!
  #3 (permalink)  
Old 06-10-2007, 04:22 PM
Somnath M
Posts: n/a
Hey

I am same person, who has asked this question.
I able to resolve the issue.

1. I have added the HTTP module in BeginRequest

that is
app.BeginRequest += new EventHandler(this.OnPreRequest);

2. instead of Server.trasfer I have used ...

context.RewritePath("...

This help me. Session is working properly.

__________________

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!
Closed Thread


Thread Tools
Display Modes

   Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -7. The time now is 10:48 PM. Powered by vBulletin
Copyright © 2000 - 2007, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO © 2007 ProgrammersTalk Sedo - Buy and Sell Domain Names and Websites project info: programmerstalk.net Statistics for project programmerstalk.net etracker® web controlling instead of log file analysis


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50