2004-03-05 06:16:15 UTC
I have 30 odd aspx pages (already built) on my website that I need to have
some validation occur before the page should load. The validation is - TEST
Id rather implement this check without touching any of the aspx files.
Reason is the usual - I dont want "same code" clutter in all pages
cause all my aspx pages have the <head> tag defined and I need to imbed the
common <script> tags inbetween the <head> tags. If i were to use page
templates- id have to remove the head tag in all my aspx files and render it
from my page template along with my <script> tags.. Also I dont want to use
includes or user controls cause that still involves touching all files.
Whats left? HttpModules.
This is for js-disabled browsers
browsers URL to the new url. The problem is that I can only implement this
in default.aspx. If somebody were to bookmark main.aspx - there would be no
check. Id be back to square one. Heres where HttpModules came in. Atleast I
Ive gradually realized that the HttpModule is a interceptor and acts similar
to a human being having the job of bouncer at some fancy club. What the
bouncer lacks here is communication skills. Heres what I mean:
client that question! So the request goes back to the client and it needs to
respond with a yes or a no for accessing the real page. How do we do this?
By request parameters being passed via the url. eg
Heres my sample code:
/// Summary description for BrowserValidator.
public class BrowserValidator : System.Web.IHttpModule
public void Init(HttpApplication application)
application.PreRequestHandlerExecute += (new
public void Dispose()
private void Application_PreRequestHandlerExecute(Object source, EventArgs
HttpApplication application = (HttpApplication)source;
HttpRequest request = application.Request;
HttpResponse response = application.Response;
//check the request
//if request variable is set to ok, allow request to continue.
//else return requested url with checker code.
if (request["ok"] != "ok")
String url = application.Request.RawUrl;
//pass through with removing "ok" from the request
private string checkerCode(string url)
StringBuilder s1 = new StringBuilder();
s1.Append("location=\"" + url + "?ok=ok\";");
s1.Append("This is for js-disabled browsers");
So now you see my little commented out response.Redirect? Im dead in the
water. Im thinking this is not even possible. I would like to remove the
ok=ok from the url cause i dont want it displayed. People could easily
bypass my validation otherwise. Yes, I know - you can get the url by looking
complete url - but thats ok. I want to make this a hindrance rather than
bullet proof. So anyways - i want to remove the ok=ok from the url and
redirect to the same page, but then my module would again test the page for
Am I making a mess of the whole thing? Is this not possible at all? Well,
there is another way - intercepting and parsing the output string to the
browser and embedding the code in there. Id rather not do that.
Any help would be greatly appreciated.