views:

152

answers:

4

I need to print out the querystring value "?type=xxx" inside my .aspx-page, why doesn't this work:

<%= Request.QueryString("type") %>

While this does:

<%= Request.QueryString(0) %>

The first prints out nothing, the second one prints out the value as expected, but it isn't always the first value I want...

Any ideas?

I redirect to "modrewrite.aspx" on 404-errors on the Custom Errors tab in IIS and then pick up the correct page depending on what whas asked for. However, it's strange it works with the indexed and not named value...

I've managed to figure out an odd solution; If I put a dummy value first, then I can pick my value up as expected.

This works: "?dummy=value&type=xxx" Now I can collect the value with <%= Request.QueryString("type") %>

A: 

This is just a cheap shot.

Try

<%= Request.QueryString["type"] %>

or

<%= Request.QueryString('type') %>
Marcus L
Worth adding Server.HtmlEncode aswell. Prevent xss :)
Si Philp
Although it isn't mentioned, `QueryString('type')` is VB syntax (it is safe to assume the posted cold complies, so it must be VB)
Kobi
The first one gives the error "Identifier expected" and the second one "Expression expected".
henrico
Ah well. As I said, just a cheap shot.I do agree with Kobi, though, your code looks right.
Marcus L
How about just trying Request["type"] - strictly speaking, you shouldn't need .QueryString.
Marcus L
Nope, no difference.
henrico
A: 

I would parse the value in my codebehind, perform any security checks on it to check for QueryString manipulation and then set it to the Text property of a Literal control on the page.

lit1.Text = Request.QueryString["type"];
Daniel Dyson
Tried that also, with no avail.
henrico
When you put a breakpoint on the line, what is contained in the Request.QueryString?
Daniel Dyson
A: 

In your aspx put a label:

<asp:Label ID="typeLabel" runat="server" />

and in your code behind assign a value to it:

protected void Page_Load(object sender, EventArgs e)
{
    typeLabel.Text = Request["type"];
}

Adapt the code behind to VB.NET if necessary

Darin Dimitrov
Tried that, doesn't work...
henrico
A: 

I've managed to figure this one out: If I put a dummy value first, then I can pick my value up as expected.

This works: "?dummy=value&type=xxx"

Now I can collect the value with <%= Request.QueryString("type") %>

Interesting.

henrico
Hello. You should add details to the question by editing it, not by adding an answer. This clearly indicates you're redirecting it wrong.
Kobi
Is there any other way to redirect that might work differently?
henrico