简体   繁体   English

当查询字符串中明显包含值时,Request.QueryString [“ parameter”]不返回任何内容

[英]Request.QueryString[“parameter”] returns nothing, when value is clearly in the query string

I have an MVC Umbraco project and I'm trying to setup a simple search form. 我有一个MVC Umbraco项目,并且我正在尝试设置一个简单的搜索表单。 The search form uses basic HTML: 搜索表单使用基本的HTML:

<form methed="GET">
    <input name="s"... />
...

In the ascx.cs file that processes the search results, I have a Page_Load method that does the following: 在处理搜索结果的ascx.cs文件中,我有一个执行以下操作的Page_Load方法:

protected void Page_Load(object sender, EventArgs e)
{
    SearchTerm = Request.QueryString["s"];
...

The problem is that Request.Query is always empty, even though the resulting URL clearly has the s parameter in it. 问题在于,即使结果URL显然带有s参数, Request.Query始终为空。

Any thoughts as to why that would be invisible to this code behind file? 关于为什么文件后面的这段代码看不到它的任何想法?

Also, to further confuse the situation, Request.RawUrl returns the url with the query string in it. 同样,为了进一步混淆这种情况, Request.RawUrl返回带有查询字符串的URL。

This happened to me using umbraco but turned out not to be an umbraco issue. 使用umbraco发生在我身上,但事实证明这不是umbraco问题。 RawUrl contained the query string but QueryString didn't. RawUrl包含查询字符串,但QueryString没有。

The problem was that I was passing a url in the query string and had forgotten to encode it. 问题是我在查询字符串中传递了一个url,却忘记了对其进行编码。 This actually didn't matter when the url being passed in the query string didn't have its own query string, but when it did I guess c# saw the query string as malformed and so was unable to populate QueryString. 当在查询字符串中传递的URL没有自己的查询字符串时,这实际上并不重要,但是当我猜到时,C#认为查询字符串格式不正确,因此无法填充QueryString。

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

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