A user is sending me a data value in a web browser -see below for example. I would like to get this value and use it downstream. I try using string val = Request.QueryString[X_ACCOUNTID] but it did not work. Any idea on how I can retrieve the value in my ASP code behind?

Dani AI

Generated

As noted, reading a GET value on the server is the right approach. The core issue here is that what you see in the browser address bar is not necessarily what the server received at the time Page_Load ran. The address bar can change (or be edited) without a new server request, and Visual Studio’s debug-run behavior can also start a request that does not include whatever you later type in the browser.

Common causes and how to check them:

  • You added the query string in the address bar after the page already loaded (or client-side code used history.pushState). If you didn’t actually reload/navigate, the server never saw the new query string. Use the browser Network tab or Fiddler to confirm the request contains the query when the page is requested.

  • Visual Studio may have launched the app using the project’s Start URL (Project Properties → Web) — that start URL may not include the query string. Either add the query string to the start URL, manually navigate after attaching the debugger, or attach the debugger to the browser process that made the request.

  • The page might be served inside a frame or you used Server.Transfer/URL rewriting so the address bar and the server request don’t match. Also check caching or proxy behavior by forcing a full reload (Ctrl+F5).

To see exactly what the server received, inspect/log the raw request values at runtime (set a breakpoint in Page_Load and view them or write them to debug/trace):

System.Diagnostics.Debug.WriteLine(Request.RawUrl);
System.Diagnostics.Debug.WriteLine(Request.Url.AbsoluteUri);
System.Diagnostics.Debug.WriteLine(Request.ServerVariables["QUERY_STRING"]);

If those are empty, the problem is upstream (browser/launch), not ASP.NET. If they show the query string but your code still finds nothing, include the exact URL you used and whether you’re running under IIS, IIS Express, or the VS Development Server — that context will point to the next troubleshooting steps. For reference on the server-side request object see HttpRequest.QueryString.

Recommended Answers

All 2 Replies

A user is sending me a data value in a web browser -see below for example. I would like to get this value and use it downstream. I try using string val = Request.QueryString[X_ACCOUNTID] but it did not work. Any idea on how I can retrieve the value in my ASP code behind?

Here is the Solution:

string val;
if(Request.QueryString.Count>0)
{
  val= Request.QueryString["X_ACCOUNTID"];
}

Here is the Solution:

string val;
if(Request.QueryString.Count>0)
{
  val= Request.QueryString["X_ACCOUNTID"];
}

Although I can see the X_ACCOUNTID value in the url, it is empty when I try to access it. In fact the entire url is missing when in debug mode in Page_Load. Any idea why the url is missing although I can see it in the address bar?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.