2

In C# and ASP.NET, I've been sending a value to another page via Request.Querystring for years, but just recently I've come against a page error that I cannot explain.

If I send a string that has

0X

in it, then the page crashes with an error

HTTP Error 404.19 - Not Found

Also I cannot get a try / catch to work, to tell me more about the issue.

I can send a string with 0X locally in VS2022 and it traces through fine, but when pushed to the live server code, it gets this issue.

So, I knocked up the simplest of .aspx pages called QSRequest.aspx to prove the issue, but I can find no reason for it.

Here's an example that works:

QSRequest.aspx?SearchValue=KDZ2X

and the same code but doesn't work:

QSRequest.aspx?SearchValue=KDZ0X

My Page_Load code:

protected void Page_Load(object sender, EventArgs e)
{
    // Get Search box value
    string SearchValue = Request.QueryString["SearchValue"];

    // Check if SearchValue is not null or empty
    if (!string.IsNullOrEmpty(SearchValue))
    {
        // display the SearchValue
        Label1.Text += "SearchValue: " + SearchValue;
    }
    else
    {
        Label1.Text += "<br/>No search value provided.";
    }
 }

On doing some research, it looks like something to do with being a protected / 'system' keyword or IIS Request Filtering (if so is there a good guide to change the settings anywhere / the correct place to edit my web.config file).

Greatly appreciate ideas if I need to encode / decode it as a work around, modify the web.config. Thanks.

3
  • 1
    If you have not seen it yet, have a look: stackoverflow.com/questions/59714161/…. Commented Jul 18 at 21:12
  • Thank you for the link, I've decided to just use a Session instead, but it does look like it is something to do with filtering, slightly annoying that the error message of 404 isn't more intuitive. Commented Jul 19 at 8:06
  • 1
    I cannot replicate the issue. It could indeed be a setting in IIS and/or Web.Config. Or do you have a URL Rewrite active that redirects to the wrong page in the background Commented Jul 19 at 10:08

1 Answer 1

0

you have to check QueryString key befor assigning it to a variable.

the correct form is:

if (Request.QueryString["SearchValue"] != null)
{
     Label1.Text += "SearchValue: " + Request.QueryString["SearchValue"];
}
else
{
    Label1.Text += "<br/>No search value provided.";
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.