473,800 Members | 2,406 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HttpContext.Cur rent.Request.Qu eryString

Hi

if I have a url/query like "localhost?a&b& c=123" then I thought I could
get these parameters and values by using
NameValueCollec tion query = HttpContext.Cur rent.Request.Qu eryString;

But if I then try "query.AllK eys" I only get two keys, namely "null"
and "c".

Is this correct behaviour? Are "a" and "b" considered to be values for
a null key - and how do I get them from the collection?
Thanks,
Peter
Jun 27 '08 #1
12 14883
Peter wrote:
Hi

if I have a url/query like "localhost?a&b& c=123" then I thought I could
get these parameters and values by using
NameValueCollec tion query = HttpContext.Cur rent.Request.Qu eryString;

But if I then try "query.AllK eys" I only get two keys, namely "null"
and "c".

Is this correct behaviour? Are "a" and "b" considered to be values for
a null key - and how do I get them from the collection?
Shouldn't the query string be: "localhost?a=&b =&c=123" ?

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Jun 27 '08 #2
Frans Bouma [C# MVP] wrote:
if I have a url/query like "localhost?a&b& c=123" then I thought I
could get these parameters and values by using
NameValueCollec tion query = HttpContext.Cur rent.Request.Qu eryString;

But if I then try "query.AllK eys" I only get two keys, namely "null"
and "c".

Is this correct behaviour? Are "a" and "b" considered to be values
for a null key - and how do I get them from the collection?

Shouldn't the query string be: "localhost?a=&b =&c=123" ?
Yes, I think you're right, the query should really look like that.

I guess I should ignore any null keys I get from AllKeys (what can I
use a null key for anyway?)

Thanks,
Peter
Jun 27 '08 #3
On Apr 25, 5:35*am, "Peter" <xdz...@hotmail .comwrote:
Frans Bouma [C# MVP] wrote:
if I have a url/query like "localhost?a&b& c=123" then I thought I
could get these parameters and values by using
NameValueCollec tion query = HttpContext.Cur rent.Request.Qu eryString;
But if I then try "query.AllK eys" I only get two keys, namely "null"
and "c".
Is this correct behaviour? Are "a" and "b" considered to be values
for a null key - and how do I get them from the collection?
* *Shouldn't the query string be: "localhost?a=&b =&c=123" ?

Yes, I think you're right, the query should really look like that.

I guess I should ignore any null keys I get from AllKeys (what can I
use a null key for anyway?)

Thanks,
Peter
Who is generating that query string?
As Frans mentioned it's wrong.

You should have default values for all your parameters, and then just
update those with values in the QS.
so all you have to do at the most is adding a if (key==null) continue;
Jun 27 '08 #4
Ignacio Machin ( .NET/ C# MVP ) wrote:
On Apr 25, 5:35*am, "Peter" <xdz...@hotmail .comwrote:
Frans Bouma [C# MVP] wrote:
if I have a url/query like "localhost?a&b& c=123" then I thought
I could get these parameters and values by using
NameValueCollec tion query =
HttpContext.Cur rent.Request.Qu eryString;
But if I then try "query.AllK eys" I only get two keys, namely
"null" and "c".
Is this correct behaviour? Are "a" and "b" considered to be
values for a null key - and how do I get them from the
collection?
* *Shouldn't the query string be: "localhost?a=&b =&c=123" ?
Yes, I think you're right, the query should really look like that.

I guess I should ignore any null keys I get from AllKeys (what can I
use a null key for anyway?)

Thanks,
Peter

Who is generating that query string?
As Frans mentioned it's wrong.

You should have default values for all your parameters, and then just
update those with values in the QS.
so all you have to do at the most is adding a if (key==null) continue;
In my program I was using AllKeys, and looping over the keys doing some
processing. Unfortunately I did not take account of the fact that a key
could be null.

A user decided to edit the query string himself, and then we got an
exception.

I did just like you said, and now check if the key is null before
processing it.

I can't really see the point in AllKeys returning a null key, but there
you go...

/Peter
Jun 27 '08 #5
It is very common to see querystrings with null key values (e.g., &ua=&bg=1 )
rather than the key not being present. Just take a look at some google
searches to see examples of this.
-- Peter
To be a success, arm yourself with the tools you need and learn how to use
them.

Site: http://www.eggheadcafe.com
http://petesbloggerama.blogspot.com
http://ittyurl.net
"Peter" wrote:
Ignacio Machin ( .NET/ C# MVP ) wrote:
On Apr 25, 5:35 am, "Peter" <xdz...@hotmail .comwrote:
Frans Bouma [C# MVP] wrote:
>
if I have a url/query like "localhost?a&b& c=123" then I thought
I could get these parameters and values by using
NameValueCollec tion query =
HttpContext.Cur rent.Request.Qu eryString;
>
But if I then try "query.AllK eys" I only get two keys, namely
"null" and "c".
>
Is this correct behaviour? Are "a" and "b" considered to be
values for a null key - and how do I get them from the
collection?
>
Shouldn't the query string be: "localhost?a=&b =&c=123" ?
>
Yes, I think you're right, the query should really look like that.
>
I guess I should ignore any null keys I get from AllKeys (what can I
use a null key for anyway?)
>
Thanks,
Peter
Who is generating that query string?
As Frans mentioned it's wrong.

You should have default values for all your parameters, and then just
update those with values in the QS.
so all you have to do at the most is adding a if (key==null) continue;

In my program I was using AllKeys, and looping over the keys doing some
processing. Unfortunately I did not take account of the fact that a key
could be null.

A user decided to edit the query string himself, and then we got an
exception.

I did just like you said, and now check if the key is null before
processing it.

I can't really see the point in AllKeys returning a null key, but there
you go...

/Peter
Jun 27 '08 #6
Peter Bromberg [C# MVP] wrote:
It is very common to see querystrings with null key values (e.g.,
&ua=&bg=1 ) rather than the key not being present. Just take a look
at some google searches to see examples of this.
In your example there are no "null keys". You have a key called "ua"
and a key called "bg".

The value for ua is empty, and the value for bg is 1.

If your query string was "&ua&bg=1" then AllKeys would return two keys:
null and "bg".

I don't really understand the point of a null key.

/Peter
Jun 27 '08 #7
There needs to be an equals (=) sign after each key name.
-- Peter
To be a success, arm yourself with the tools you need and learn how to use
them.

Site: http://www.eggheadcafe.com
http://petesbloggerama.blogspot.com
http://ittyurl.net
"Peter" wrote:
Peter Bromberg [C# MVP] wrote:
It is very common to see querystrings with null key values (e.g.,
&ua=&bg=1 ) rather than the key not being present. Just take a look
at some google searches to see examples of this.

In your example there are no "null keys". You have a key called "ua"
and a key called "bg".

The value for ua is empty, and the value for bg is 1.

If your query string was "&ua&bg=1" then AllKeys would return two keys:
null and "bg".

I don't really understand the point of a null key.

/Peter
Jun 27 '08 #8
Peter Bromberg [C# MVP] wrote:
There needs to be an equals (=) sign after each key name.
Yes indeed. I found that out. But what to do if a user enters the query
string in the browser....

It seems strange to me that (1) the browser (internet explorer) sends
an "illegal" query string; and (2) the AllKeys property returns a key
which is null - using a null key to retrieve a value from the
NameValueCollec tion results in an error of course.

/Peter
Jun 27 '08 #9
I think it would be pretty rare for a web application that expects a user to
be creating their "own" querystrings. You can type whatever gobbledegook you
want after a URI in the Address Bar of your browser, and the browser will
happily attempt to retrieve the resource for you. Cheers.
-- Peter
To be a success, arm yourself with the tools you need and learn how to use
them.

Site: http://www.eggheadcafe.com
http://petesbloggerama.blogspot.com
http://ittyurl.net
"Peter" wrote:
Peter Bromberg [C# MVP] wrote:
There needs to be an equals (=) sign after each key name.

Yes indeed. I found that out. But what to do if a user enters the query
string in the browser....

It seems strange to me that (1) the browser (internet explorer) sends
an "illegal" query string; and (2) the AllKeys property returns a key
which is null - using a null key to retrieve a value from the
NameValueCollec tion results in an error of course.

/Peter
Jun 27 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
11410
by: MarkMurphy | last post by:
In a barebones website with one page, checking HttpContext.Current.Request.UserLanguages.Length in Page_Load of an ASPX page in the VS IDE in codebehind shows a value of 1. Then when I refresh the page with F5 from the browser it goes to the expected 16 -- the number of languages I have defined in IE6. I'm globalizing a site and could swear this was working at one point. I use the value at to pick the user's language. On affected...
2
1944
by: Francois Malgreve | last post by:
hello guys, I have some helper class in my ASP.NET pplication who basically contains static methods. I used them as helper methods to do small jobs that I can use at many places in my code. As those classes methods are static, they are never associated with any instance, then not assoicated with any HttpRequest neither. Nevertheless in some case I ended up myself passing the Session object to my static methods to be able to get some...
7
2749
by: Keith Patrick | last post by:
After completely giving up on finding some way in my ASP.Net app to take a query string URL and redirect to it as a POST instead, I went with a system like so: Upon "redirection," all the QueryString pairs are placed in HttpContext.Current.Items and retrieved with a wrapper for Request.Params that includes checks there. This works in general instances, but one problem has come up that has me stuck: since the stuff is in the context and...
1
6519
by: josephpage | last post by:
I have a Visitor class that is defined in a class library. The class has lots of parameters that are pulled from the QueryString, the ReferrerUrl, Cookies, the Session object, etc... I would like to make a constructor for the Visitor class that accepts an HttpContext instance from within Session_Start in Global.asax.cs as an input parameter. The problem is that I can't figure out how to reference HttpContext from within my Visitor...
3
2976
by: Steve Franks | last post by:
Is there a way I can extend the HttpContext or one of its subclasses to include a property that exposes a custom class of mine to all ASP.NET pages? More specifically, I'd like to use a HttpModule to initialize an instance of a custom class, and have this class exposed directly through the HttpRequest for the current user through a property I add to the HttpRequest object. For example, I'd like my developers to be able to use this...
2
12020
by: Dave | last post by:
After some digging, I discovered HttpContext.Current.Session is null when trying to access a session variable, username, in my upload.cs code which is in the App_Code folder. I just determined that I can't because HttpContext.Current.Session is null. (HttpContext.Current is fine though) I think there may be another server side method interfering with my ability to access the session.
4
11901
by: msch-prv | last post by:
Hello. I am trying to use caching to populate a datalist. The select method of the associated objectdatasource calls up GetRecipePageByRecipeCatID() to request the proper data (I am using custom paging at SQL level so there is a paging idx as well). The code works fine when caching is edited out. Problem. The cache object is only created the first time around. When the dtl ia refreshed, th HttpContext.cache object always returns...
3
13474
by: Brett R. Wesoloski | last post by:
I am having problems using HttpContext.Current.Request.Url.Host. I have some code that does this... if (HttpContext.Current != null) { subdomain = HttpContext.Current.Request.Url.Host; }
3
8913
by: Madhur | last post by:
Hello I am delivering an asp.net 2.0 application to my customer. I need to know, If I need to check for the condition of HttpContext.Current to be null in my business logic. I have extensively used Cache and Session objects, and currently I assume HttpContext.Current object to be existent. Also, since I do not have this check, some of my unit test cases fail because there is no HttpContext for them.
0
9690
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10505
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10253
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10033
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7576
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5471
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.