473,396 Members | 1,666 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to detect page post back in HttpModule?

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>
/// Summary description for PermissionChecker.
/// </summary>
public class PermissionChecker : IHttpModule {
// The stored application
private HttpApplication myApp;

public PermissionChecker() {
}

public void Init(HttpApplication app) {
// Store off the application object
myApp = app;
// Wire up our event handlers
myApp.AuthorizeRequest += new EventHandler(myApp_AuthorizeRequest);
}

public void Dispose() {
}

private void myApp_AuthorizeRequest(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.Name.Length > 0) {
userID = Convert.ToInt32(myApp.Context.User.Identity.Name);
} else {
userID = 0;
}
string url = myApp.Request.Url.AbsolutePath;
}
}
}

--

WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy
Nov 16 '05 #1
3 6803
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********@marketrend.com> a écrit dans le message de
news:O9**************@TK2MSFTNGP12.phx.gbl...
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>
/// Summary description for PermissionChecker.
/// </summary>
public class PermissionChecker : IHttpModule {
// The stored application
private HttpApplication myApp;

public PermissionChecker() {
}

public void Init(HttpApplication app) {
// Store off the application object
myApp = app;
// Wire up our event handlers
myApp.AuthorizeRequest += new EventHandler(myApp_AuthorizeRequest);
}

public void Dispose() {
}

private void myApp_AuthorizeRequest(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.Name.Length > 0) {
userID = Convert.ToInt32(myApp.Context.User.Identity.Name);
} else {
userID = 0;
}
string url = myApp.Request.Url.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****************@TK2MSFTNGP10.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********@marketrend.com> a écrit dans le message de
news:O9**************@TK2MSFTNGP12.phx.gbl...
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>
/// Summary description for PermissionChecker.
/// </summary>
public class PermissionChecker : IHttpModule {
// The stored application
private HttpApplication myApp;

public PermissionChecker() {
}

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

EventHandler(myApp_AuthorizeRequest); }

public void Dispose() {
}

private void myApp_AuthorizeRequest(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.Name.Length > 0) {
userID = Convert.ToInt32(myApp.Context.User.Identity.Name);
} else {
userID = 0;
}
string url = myApp.Request.Url.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.com> wrote in message
news:zo*********************@wards.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****************@TK2MSFTNGP10.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********@marketrend.com> a écrit dans le message de
news:O9**************@TK2MSFTNGP12.phx.gbl...
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>
/// Summary description for PermissionChecker.
/// </summary>
public class PermissionChecker : IHttpModule {
// The stored application
private HttpApplication myApp;

public PermissionChecker() {
}

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

EventHandler(myApp_AuthorizeRequest); }

public void Dispose() {
}

private void myApp_AuthorizeRequest(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.Name.Length > 0) {
userID = Convert.ToInt32(myApp.Context.User.Identity.Name);
} else {
userID = 0;
}
string url = myApp.Request.Url.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
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 {...
1
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;...
1
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...
6
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"...
13
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...
2
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...
2
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...
1
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: ...
3
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...
0
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...
0
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...

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.