QueryString problem in .aspx - prints out nothing
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 ex开发者_StackOverflow中文版pected.
This works: "?dummy=value&type=xxx" Now I can collect the value with <%= Request.QueryString("type") %>
This is just a cheap shot.
Try
<%= Request.QueryString["type"] %>
or
<%= Request.QueryString('type') %>
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"];
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
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.
精彩评论