Click here to Skip to main content
15,909,953 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Let us consider a sample website application and running in local host.say for example www.asdf.com . when ever the user hitting the url in browser

Can it can be captured by inheriting ihttp handler or ihttp module to our class

If the url has been hitted by changing www.asdf.com?t=value is it possible to take that value.

In java this concept is used as servelet filters . Is there any thing like that in dotnet

waiting for your responses
Posted

In ASP.Net the IHttpModule interface exposes the following method:

C#
public void Init(System.Web.HttpApplication context)


The HttpApplication object contains the current execution context which includes the Request, Response, Session and Server objects.

You can gain access to the same object anywhere in your ASP.Net code by using the following:

C#
System.Web.HttpContext.Current


You can access the value you're looking for like this:

C#
string t = context.Request.QueryString["t"];


You can then do the redirect in this way:

C#
string t = context.Request.QueryString["t"];
if(t == null) 
  context.Response.Redirect(context.Requset.Url.ToString() + "?t=value";


This is a very basic implementation if you're expecting other query string values you may need more complicated rules.

IHttpHandler and IHttpModule are used for defining custom Handlers and custom Modules. These are code libraries which are generally designed to be reusable simply by registering them in IIS. So they essentially modify behaviour without modifying the website code.

If this is a one off process for a single application you may be better off using your Global.asax file. You can add the following method:

C#
protected void Application_BeginRequest(object sender, EventArgs e)


This will then be called every time your application receives a request. Although you must be careful as with all these methods requests for images and js files e.t.c. will also cause the code to be executed.
 
Share this answer
 
v3
Comments
gowthammanju 7-Jun-12 6:18am    
is there any java filter equivalent concept in dotnet

ya i agree with you but i need how can i run and check it
1. create an HTTP module
2. Subscribe for BeginRequest event.
3. the Copntext.Request.QuryString will give you the query string parameter.

Details on how to implement and the fundamentals of Modules can be found here

Implementing HTTPHandler and HTTPModule in ASP.NET[^]
 
Share this answer
 
Comments
gowthammanju 7-Jun-12 6:30am    
Ya thanks will try now
is there any thing equivalent java filters in dotnet

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900