Access Request.QueryString in Master Page?

J

james

Hey Guys,

Do you have any idea how to acces Request.QueryString in a MasterPage?
I need to use it to modify my sitemap.

My code is:

public partial class MasterPage : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
SiteMap.SiteMapResolve += new
SiteMapResolveEventHandler(this.ResolveAdapter);
}

SiteMapNode ResolveAdapter(object sender, SiteMapResolveEventArgs
e)
{
SiteMapNode currentNode = SiteMap.CurrentNode.Clone(true);
string realm =
ContentPlaceHolder1.Page.Request.QueryString["realm"];
currentNode.Url += "?realm=" + realm;
return currentNode;
}
 
M

Mark Fitzpatrick

Don't forget to test to see if the Request.QueryString[] array item is not
null before you access it, otherwise you're going to end up with
nullreference errors when the querystring variable isn't present or
misspelled.
 
L

Laurent Bugnion

Hi,

Mark said:
Don't forget to test to see if the Request.QueryString[] array item is not
null before you access it, otherwise you're going to end up with
nullreference errors when the querystring variable isn't present or
misspelled.

Just to be nitpicking, the QueryString array won't be null if the
variable is mispelled, so you should also test if the variable itself is
not null:

if ( this.Request != null
&& this.Request.QueryString != null
&& this.Request.QueryString[ "realm" ] != null )
{
// Do some work
}

HTH,
Laurent
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top