c00000fd
c00000fd

Reputation: 22283

HTTP parameter with the name 'url' causes strange result for my Web App

I asked this before but I'm stuck with another issue. Say, if I load my page like so:

http://localhost:57845/api.ashx?v=123&usr=&url=

and then try to do:

string strUser = context.Request["usr"];
string strURL = context.Request["url"];

both strUser and strURL will be set to "", which I would expect.

But if call it like this:

http://localhost:57845/api.ashx?v=123

strUser will be null, which I would also expect, but strURL will be set to "/api.ashx".

Why is that???

Upvotes: 0

Views: 115

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1501163

I believe this is coming from the ServerVariables part of the request. You'd likewise get a value if you asked for remote_addr or any of the other server variables supported by IIS (assuming you're coming through IIS).

If you only want to get parameters from the query string, use the QueryString property:

string strUrl = context.Request.QueryString["url"];

(I'd also strongly recommend that you get rid of the type-prefixes on your variable names, but that's a different matter.)

Upvotes: 3

Related Questions