473,796 Members | 2,462 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

URL Mapping and HTTPModule , a SessionState problem

4 New Member
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 URLCheckingModu le for URL checking.
This is settings in my web.config file

<httpModules>
<add name="Session" type="System.We b.SessionState. SessionStateMod ule"/>
<add name="URLChecki ng" type="UserProfi leModule"/>
</httpModules>
<pages enableSessionSt ate="true" />
</system.web>
</configuration>

This is my class code
using System;
using System.Data;
using System.Configur ation;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;
using System.IO;
using System.Web.Sess ionState;

public class UserProfileModu le : IHttpModule
{
public void Init(HttpApplic ation app)
{
app.PreRequestH andlerExecute += new EventHandler(th is.OnPreRequest );
}

private void OnPreRequest(ob ject sender, EventArgs e)
{

HttpContext context = HttpContext.Cur rent;
HttpRequest request = context.Request ;
string FilePath = request.FilePat h;
string ext = Path.GetExtensi on(FilePath);

if (string.IsNullO rEmpty(ext) && !FilePath.EndsW ith("/"))
{
// suppose URL is http://xyz.com/somnath/
// and empty Extension
string q = request.QuerySt ring.ToString() ;
string path = request.FilePat h + "/" + (string.IsNullO rEmpty(q) ? "" : q);
context.Server. Transfer("show_ user.aspx" );
}
else
{
if (FilePath.EndsW ith("/"))
{
string dPath;
dPath = context.Server. MapPath(FilePat h);
if (Directory.Exis ts(dPath) == false)
{
FilePath = FilePath.Remove (FilePath.Lengt h - 1, 1);
context.Respons e.Redirect(File Path);
}
}
}
}

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 enableSessionSt ate is set to true, either in a configuration file or in the Page directive. Please also make sure that System.Web.Sess ionStateModule 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 “PreRequestHand lerExecute” ,

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.
May 29 '07 #1
0 1745

Sign in to post your reply or Sign up for a free account.

Similar topics

4
3429
by: Ian Turner | last post by:
Hi, In an attempt to get every request for a particular virtual directory to go through ASP.NET I've been trying to add a wildcard application mapping. The scenario is that any url for that VD, whether it resolves to an actual file or not, can be intercepted by an HttpModule and ultimately redirected (using RewritePath) to a resource of my choosing. I was hoping that just adding the wildcard mapping to the IIS VD would work. But it...
7
2580
by: nail | last post by:
Folks, I develop a HttpModule and it works correct, but one problem is occurs. After I register the httpmodule in the web.config, my pages (not testing http://localhost/site but http://my_machine_name/site) show problems when refresh the page. I guess some kind of javascript problems with the postback methods. Someone has any idea how can i fix it? Thanks
0
1123
by: Ian Suttle | last post by:
I have created an HTTPModule for error handling, which I only want to handle a specified directory structure. In the root of my application, I have altered the web.config file as follows: <configuration> <location path="dir/dir/dirToHandle"> <system.web> <httpModules> <add name="ErrorHandler" type="ErrorModule.ErrorHandler, ErrorModule" /> </httpModules>
4
3912
by: Danny W | last post by:
Hi There! Is it possible to use HttpModule to replace the built-in ASP.NET Session object? I want to write a HttpModule that will handle storing and retrieving of session values from an external database. For example, when a page set values to Session object such as Session("somevar")=1 then I want my HttpModule to get notified and store the value into the external database. The same for "getting" the variable, I want my own...
1
1871
by: Mike Kline | last post by:
Hi There! How do I make the Objects in the custom made HttpModule available to ASPX page or ASCX controls without requiring an object reference? For example, SessionState HttpModule made the Session object available throughout the ASP.NET application without needing to have a reference to SessionState HttpModule. So how do I expose my own objects from my own custom HttpModule available throughout the ASP.NET application?
2
2144
by: Simon-Pierre Jarry | last post by:
Hi, I created a custom HttpModule for managing the security of my application. in "Init" sub, I regsiter the events doing that : Public Sub Init(ByVal context As System.Web.HttpApplication) Implements IHttpModule.Init httpApp = context
5
7313
by: Miguel | last post by:
ey, I m trying to make a new httpmodule but the session object is null. I m implementing IReadOnlySessionState but it keep on being null. I m novice in this enviroment, does anybody know what's happening? thanks Miguel
0
1414
by: Thomas | last post by:
in .net 1.1 we successfully use a HttpModule to catch 404 / 403.1 html errors. after migrating to .net 2.0, this modules is broken in a very, very strange way. we have defined a wildcard applicatio mapping to the .net 2.0 isapi dll: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll with "check if file exists" disabled. the HttpModule "RedirectMissing" is called upon every request to the
7
2986
by: Tomasz | last post by:
Hello Developers, I have an interesting problem. How, or when can I access SessionState from HttpModule? It seems that session state is only available when *.aspx page is requested. It is not available for other resource types like *.gif files etc. Is there any way I can force session state to load, even when it is not *.aspx page being requested?
0
9683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9529
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10457
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10176
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10013
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5576
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4119
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3733
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2927
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.