Skip to main content
 首页 » 编程设计

c#之Microsoft.AspNetCore.Mvc.WebApiCompatShim 中缺少 Request.GetQueryNameValuePairs()

2024年02月27日26zengkefu

Microsoft.AspNetCore.Mvc.WebApiCompatShim 没有 Request.GetQueryNameValuePairs() 定义。我有一个要迁移到 .Net Core 的现有项目。除了我有一个包含 Request.GetQueryNameValuePairs() 的代码片段外,其他一切都可以与 Microsoft.AspNetCore.Mvc.WebApiCompatShim 一起正常工作。

Intellisense 显示以下信息:

CS1061 'HttpRequestMessage' does not contain a definition for 'GetQueryNameValuePairs' and no extension method 'GetQueryNameValuePairs' accepting a first argument of type 'HttpRequestMessage' could be found (are you missing a using directive or an assembly reference?)

谁能建议我如何解决这个问题?

请您参考如下方法:

这将为您提供查询字符串的解析版本作为 IQueryCollection:

HttpContext.Current.Request.Query