请看下面的代码。在handler.asxh
中。
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "application/json";
new RequestManagementFacade().PinRequest(Int32.Parse(context.Request.QueryString["requestId"]), (Boolean.Parse(context.Request.QueryString["isPinned"])));
}
这显示以下错误:
Value cannot be null. Parameter name: String
当我检查上下文请求查询字符串时,正在传递值,但是,代码在此阶段中断。
此处理程序将连接到业务逻辑层。
有值传递,因为我检查了上下文请求查询字符串
我强烈怀疑您的诊断不正确。价值观不会神奇地消失-您需要质疑您的假设。不过,这很容易调试。我建议将您的代码更改为:
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "application/json";
string requestId = context.Request.QueryString["requestId"];
string isPinned = context.Request.QueryString["isPinned"];
var facade = new RequestManagementFacade();
facade.PinRequest(Int32.Parse(requestId), Boolean.Parse(isPinned));
}
然后really简单地逐步了解并发现正在发生的事情。
[context.Request.QueryString["requestId"]
或context.Request.QueryString["isPinned"]
可能未返回有效的字符串值。检查两个值是否以正确的ID在查询字符串中传递,这些ID当然是requestId
和isPinned
。
将值传递给处理程序时很好解决,我将其插入为
"PinRequest.ashx?="+requestId+isPinned"
哪个给了我结果2True
所以我意识到打ic是不包括字符串名
"PinRequest.ashx?requestId=" + this._requestId + "&isPinned=" + this._isPinned
感谢您的帮助
LeviBotelho,谢谢您让我检查了我作为JavaScript进行检查时缺少的内容