Groups | Blog | Home
all groups > asp.net > april 2004 >

asp.net : How to detect page post back in HttpModule?


Hardy Wang
4/21/2004 11:01:10 PM
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

Hardy Wang
4/22/2004 8:33:26 AM
Good idea, thanks a lot!

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy
[quoted text, click to view]

matt
4/22/2004 9:23:23 AM
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

[quoted text, click to view]

Patrice
4/22/2004 9:55:42 AM
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" <hardy_wang@marketrend.com> a écrit dans le message de
news:O9E9SXBKEHA.2776@TK2MSFTNGP12.phx.gbl...
[quoted text, click to view]

AddThis Social Bookmark Button