Querystring

  • Thread starter Thread starter Jose
  • Start date Start date
J

Jose

Hi All,

I want to ensure that a querystring parameter is included for every
request (TabID). If this parameter does not exist I want to redirect
the use to the default url (/Default.aspx?TabID=1). Previously, in
ASP.Net 1.1 I processed this within the BeginRequest event in
Global.asax.cs. I am now using ASP.Net 2.0 so I was wanting some advice
how best to achieve this - do I need to write a httphandler or
something? Any help is most appreciated.

Kind regards,
Jose
 
In a simpler way, checking the Page.QueryString.Count will give you
whether any query string passed with url or not. So, based on this you
can go ahead and check the passed TabId or redirect to default page.

The same thing may be kept in BeginRequest event. It doesn't matters
where you keeping this code. Both will do same work.
 
Why would you want to do this? If you want to persist some value accross the
session then save it in a session variable? Users can manipulate the
querystring.
 
Jose,
This can be done in a single line of code in the Page_Load handler:

if(Request.QueryString["TabId"]==null) Response.Redirect("Yourpagehere.aspx");

Peter
 
Back
Top