473,569 Members | 2,704 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to detect page post back in HttpModule?

Hi,
I have a HttpModule in my ASP.NET application, in AuthorizeReques t event, I
want to detect if page is posted back. Is there a way?
using System;
using System.Web;

namespace MyModule {
/// <summary>
/// Summary description for PermissionCheck er.
/// </summary>
public class PermissionCheck er : IHttpModule {
// The stored application
private HttpApplication myApp;

public PermissionCheck er() {
}

public void Init(HttpApplic ation app) {
// Store off the application object
myApp = app;
// Wire up our event handlers
myApp.Authorize Request += new EventHandler(my App_AuthorizeRe quest);
}

public void Dispose() {
}

private void myApp_Authorize Request(object sender, EventArgs e) {
// I NEED TO DETECT POST BACK, IF SO I DON'T WANT TO RUN AGAIN

int userID;
if (myApp.Context. User.Identity.N ame.Length > 0) {
userID = Convert.ToInt32 (myApp.Context. User.Identity.N ame);
} else {
userID = 0;
}
string url = myApp.Request.U rl.AbsolutePath ;
}
}
}

--

WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy
Nov 16 '05 #1
3 6810
Perhaps by testing the REQUEST_METHOD server variable ? A postback is likely
always a POST while you'll have a GET in other cases ?

That said I'm not sure it's the right approach (POSTs would be always
considered as authenticated ?)

Patrice

"Hardy Wang" <ha********@mar ketrend.com> a écrit dans le message de
news:O9******** ******@TK2MSFTN GP12.phx.gbl...
Hi,
I have a HttpModule in my ASP.NET application, in AuthorizeReques t event, I want to detect if page is posted back. Is there a way?
using System;
using System.Web;

namespace MyModule {
/// <summary>
/// Summary description for PermissionCheck er.
/// </summary>
public class PermissionCheck er : IHttpModule {
// The stored application
private HttpApplication myApp;

public PermissionCheck er() {
}

public void Init(HttpApplic ation app) {
// Store off the application object
myApp = app;
// Wire up our event handlers
myApp.Authorize Request += new EventHandler(my App_AuthorizeRe quest);
}

public void Dispose() {
}

private void myApp_Authorize Request(object sender, EventArgs e) {
// I NEED TO DETECT POST BACK, IF SO I DON'T WANT TO RUN AGAIN

int userID;
if (myApp.Context. User.Identity.N ame.Length > 0) {
userID = Convert.ToInt32 (myApp.Context. User.Identity.N ame);
} else {
userID = 0;
}
string url = myApp.Request.U rl.AbsolutePath ;
}
}
}

--

WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy

Nov 16 '05 #2
You could also check if the referrer is the same as the requested page
by using the HTTP_REFERER server variable, that in combination with the
REQUEST_METHOD being a POST should confirm that the page is a postback.

Matt
http://www.3internet.co.uk

"Patrice" <no****@nowhere .com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Perhaps by testing the REQUEST_METHOD server variable ? A postback is likely always a POST while you'll have a GET in other cases ?

That said I'm not sure it's the right approach (POSTs would be always
considered as authenticated ?)

Patrice

"Hardy Wang" <ha********@mar ketrend.com> a écrit dans le message de
news:O9******** ******@TK2MSFTN GP12.phx.gbl...
Hi,
I have a HttpModule in my ASP.NET application, in AuthorizeReques t event,
I
want to detect if page is posted back. Is there a way?
using System;
using System.Web;

namespace MyModule {
/// <summary>
/// Summary description for PermissionCheck er.
/// </summary>
public class PermissionCheck er : IHttpModule {
// The stored application
private HttpApplication myApp;

public PermissionCheck er() {
}

public void Init(HttpApplic ation app) {
// Store off the application object
myApp = app;
// Wire up our event handlers
myApp.Authorize Request += new

EventHandler(my App_AuthorizeRe quest); }

public void Dispose() {
}

private void myApp_Authorize Request(object sender, EventArgs e) {
// I NEED TO DETECT POST BACK, IF SO I DON'T WANT TO RUN AGAIN

int userID;
if (myApp.Context. User.Identity.N ame.Length > 0) {
userID = Convert.ToInt32 (myApp.Context. User.Identity.N ame);
} else {
userID = 0;
}
string url = myApp.Request.U rl.AbsolutePath ;
}
}
}

--

WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy


Nov 16 '05 #3
Good idea, thanks a lot!

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy
"matt" <gr************ @hitscricket.co m> wrote in message
news:zo******** *************@w ards.force9.net ...
You could also check if the referrer is the same as the requested page
by using the HTTP_REFERER server variable, that in combination with the
REQUEST_METHOD being a POST should confirm that the page is a postback.

Matt
http://www.3internet.co.uk

"Patrice" <no****@nowhere .com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Perhaps by testing the REQUEST_METHOD server variable ? A postback is

likely
always a POST while you'll have a GET in other cases ?

That said I'm not sure it's the right approach (POSTs would be always
considered as authenticated ?)

Patrice

"Hardy Wang" <ha********@mar ketrend.com> a écrit dans le message de
news:O9******** ******@TK2MSFTN GP12.phx.gbl...
Hi,
I have a HttpModule in my ASP.NET application, in AuthorizeReques t event,
I
want to detect if page is posted back. Is there a way?
using System;
using System.Web;

namespace MyModule {
/// <summary>
/// Summary description for PermissionCheck er.
/// </summary>
public class PermissionCheck er : IHttpModule {
// The stored application
private HttpApplication myApp;

public PermissionCheck er() {
}

public void Init(HttpApplic ation app) {
// Store off the application object
myApp = app;
// Wire up our event handlers
myApp.Authorize Request += new

EventHandler(my App_AuthorizeRe quest); }

public void Dispose() {
}

private void myApp_Authorize Request(object sender, EventArgs e) {
// I NEED TO DETECT POST BACK, IF SO I DON'T WANT TO RUN AGAIN

int userID;
if (myApp.Context. User.Identity.N ame.Length > 0) {
userID = Convert.ToInt32 (myApp.Context. User.Identity.N ame);
} else {
userID = 0;
}
string url = myApp.Request.U rl.AbsolutePath ;
}
}
}

--

WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy



Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1942
by: Hardy Wang | last post by:
Hi, I have a HttpModule in my ASP.NET application, in AuthorizeRequest event, I want to detect if page is posted back. Is there a way? using System; using System.Web; namespace MyModule { /// <summary>
1
6252
by: Greg Hurlman | last post by:
Is it possible to redirect to an IIS 401 or 403 error page by setting the Response.StatusCode in an HttpModule? Right now, my code look like: e.Context.Response.StatusCode = 401; e.Context.Response.End(); This passes back the proper headers, but fails to produce an error page on the client side. Is it to late for IIS to respond with an...
1
1856
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...
6
5572
by: David Bowey | last post by:
Hi There! I'm writing a custom HttpHandler to create watermarks on my PNG images of my website. So typically, a PNG image is linked in an ASPX page as follows... <img src="images/test.png" alt="testing" /> So I created an HttpHanlder to handle PNG images, have mapped the PNG extension in the IIS and also added the HttpModule section in...
13
1495
by: tshad | last post by:
Is there a way to run a script or function on entry of each page without having to put a call in each page? Periodically, I find something I want to do each time a page is entered and I have to go into each page and add a line or 2 in my asp.net code. That's a lot of pages and I could easily miss one. For example, I have a user object...
2
2602
by: walter | last post by:
Hi there , for sure httpmodule can be hooked up with HttpApplication event. But I'm wondering if it's poissible to trigger a httpModule in the page event ,like Page.Init(). Since request handler will be different among http/aspx, I hardly see it's possible. But may be someone knows. Reason I want to do this is because I like the plugin...
2
4573
by: walter | last post by:
Hi there, I know there is pool of HttpApplications, and for each request coming in, HttpRuntime will dedicate one from pool to serve the request. My questions are : 1. since HttpModule is plug into the process, does each instance of HttpApplication keep its own set of HttpModule instance or HttpModules are shared among all HttpApplication...
1
11124
by: =?Utf-8?B?SmVycnkgSg==?= | last post by:
I have an aspx page that normally gets called via an HTTP Post from another web page. For example, the calling page (page1.aspx) calls page2.aspx with a querystring from javascript like so: http.open('post', 'page2.aspx?action=generate'); When page2.aspx loads, the action=generate tells the page to begin performing a process that takes...
3
2728
by: =?Utf-8?B?UGF0UA==?= | last post by:
We have a site that gets many requests for nonexistent pages, files and folders. We want those requests redirected to the index page. However, for static files (i.e. images and some other extensions) we do not want to redirect and in that case want to return nothing. We had been using the 404 error page to redirect but need to discriminate...
0
7924
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. ...
0
8122
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7673
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...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5513
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2113
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
0
937
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...

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.