简体   繁体   English

如果是第一次加载页面,Umbraco Request.QueryString为null

[英]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. 我支持Umbraco 4.9.0站点遇到问题,其中Request上的QueryString属性始终为null,但仅在第一次加载页面时。 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: 在代码隐藏中,在Page_Load方法上,我试图获取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. 例如,我第一次点击上面的URL时,id为null。 If I immediately hit the URL again, id is set to be the value you'd expect. 如果我再次立即点击URL,则将id设置为您期望的值。

Furthermore, if I stop and restart the web app via Visual Studio, the id variable continues to work as expected. 此外,如果我通过Visual Studio停止并重新启动Web应用程序,则id变量将继续按预期工作。 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. 我还注意到Request.UrlReferrer为null,但Request.Url是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 ClientCertificate
  • ServerVariables 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. 您可能从“FORM”事件后获取此变量...因此它将位于Request.Form [“id”] ....而不是查询字符串中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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