简体   繁体   中英

Umbraco Request.QueryString is null if it's the first time the page is loaded

I have a maddening problem (aren't they all?).

I am supporting an Umbraco 4.9.0 site that is experiencing an issue where the QueryString property on the the Request is always null, but only the first time the page is loaded. For example,

www.site.com/download.aspx?id=d99fe4df-28d9-4565-b444-b42499fcefd3

In the code-behind, on the Page_Load method, I am attempting to get the id:

var id = Request.QueryString["id"];

This works except the very first time the page loads. For example, the first time I hit the above URL, id is null. If I immediately hit the URL again, id is set to be the value you'd expect.

Furthermore, if I stop and restart the web app via Visual Studio, the id variable continues to work as expected. However, if I simply modify the code base at all (example below), it will again pass a non-populated query string the first time, and work after any time that.

var test = "my modification test";
var id = Request.QueryString["id"];

I also noticed Request.UrlReferrer is null, however Request.Url is www.site.com/download.aspx.

Any help is much appreciated!

instead of

var id = Request.QueryString["id"];

try

var id = Request["id"];

what it does? it will try to find this request variable from request object in order of

  • QueryString
  • Form
  • Cookies
  • ClientCertificate
  • ServerVariables

it is possible that you are getting this variable from the " FORM " post event ... so it will be in the Request.Form["id"] .... and not in query string.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM