HttpRequest没有定义Params

时间:2022-10-06 16:54:05

I'm using .NET Core 2.0.2 to create an ASP.NET webapp in C#.

我正在使用。net Core 2.0.2创建一个ASP。网络应用在c#中。

Everytime I use Request.Url in my controllers, dotnet run outputs an error:

每次我使用的要求。Url在我的控制器中,dotnet run输出一个错误:

error CS1061: 'HttpRequest' does not contain a definition for 'Url' and no extension method 'Url' accepting a first argument of type 'HttpRequest' could be found

错误CS1061:“HttpRequest”不包含“Url”的定义,也找不到接受“HttpRequest”类型的第一个参数的扩展方法“Url”

The same thing happens with Request.Params. Even though the .NET documentation says there is a getter for the Params property.

Request.Params也是如此。尽管。net文档说明了Params属性的getter。

I managed to find a workaround for Request.Url: I use the Request.GetUri() method. However I couldn't find such a replacement for Request.Params.

我设法找到了一个变通办法。Url:我使用Request.GetUri()方法。但是,我找不到这样一个替代request。params。

Here are my using statements:

以下是我的使用说明:

using System;
using System.Diagnostics;
using area.Models;
using Microsoft.AspNetCore.Identity;
using System.Threading.Tasks;
using Microsoft.ApplicationInsights.AspNetCore.Extensions;
using Microsoft.AspNetCore.Mvc;
using Tweetinvi;
using Tweetinvi.Models;

Why am I getting those errors? Do you know a fix? Otherwise, do you have a workaround to get Request.Params?

我为什么会犯这些错误?你知道解决方法吗?否则,您是否有一个获取Request.Params的变通方法?

3 个解决方案

#1


2  

The stuff you used to get from generic request params is accessible in specific properties of Request like Query, Cookies, Form etc.

从通用请求解析中获得的内容可以在查询、cookie、表单等请求的特定属性中访问。

If you are trying to access a querystring item value, you may use the Request.Query property.

如果您试图访问一个querystring项值,您可以使用请求。查询属性。

var v = Request.Query["oauth_verifier"];

You can use the TryGetValue method on the collection to get the value if it exist.

您可以使用集合上的TryGetValue方法来获取该值(如果该值存在)。

if (Request.Query.TryGetValue("oauth_verifier",out StringValues val))
{
    var theValue = val[0];
    var orUseThis = val.ToString();
    // Use theValue as needed
}

#2


1  

HttpRequest class is defined (in different ways) in System.Web and in Microsoft.AspNetCore.Http namespaces. The former has Params property the latter doesn't. Debug to find what kind HttpRequest you have (and add proper using...).

HttpRequest类在系统中定义(以不同的方式)。网络和Microsoft.AspNetCore。Http命名空间。前者有Params属性,后者没有。调试以找到您拥有的类型HttpRequest(并添加适当的使用…)。

#3


0  

HttpRequest.Params are collection of (QueryString, Form and Cookies) so you can get them:

HttpRequest。Params是(QueryString、Form和cookie)的集合,所以您可以得到它们:

HttpContext.Request.Cookies;
HttpContext.Request.QueryString;
HttpContext.Request.Form;

HttpRequest.Params Property

HttpRequest。参数属性

#1


2  

The stuff you used to get from generic request params is accessible in specific properties of Request like Query, Cookies, Form etc.

从通用请求解析中获得的内容可以在查询、cookie、表单等请求的特定属性中访问。

If you are trying to access a querystring item value, you may use the Request.Query property.

如果您试图访问一个querystring项值,您可以使用请求。查询属性。

var v = Request.Query["oauth_verifier"];

You can use the TryGetValue method on the collection to get the value if it exist.

您可以使用集合上的TryGetValue方法来获取该值(如果该值存在)。

if (Request.Query.TryGetValue("oauth_verifier",out StringValues val))
{
    var theValue = val[0];
    var orUseThis = val.ToString();
    // Use theValue as needed
}

#2


1  

HttpRequest class is defined (in different ways) in System.Web and in Microsoft.AspNetCore.Http namespaces. The former has Params property the latter doesn't. Debug to find what kind HttpRequest you have (and add proper using...).

HttpRequest类在系统中定义(以不同的方式)。网络和Microsoft.AspNetCore。Http命名空间。前者有Params属性,后者没有。调试以找到您拥有的类型HttpRequest(并添加适当的使用…)。

#3


0  

HttpRequest.Params are collection of (QueryString, Form and Cookies) so you can get them:

HttpRequest。Params是(QueryString、Form和cookie)的集合,所以您可以得到它们:

HttpContext.Request.Cookies;
HttpContext.Request.QueryString;
HttpContext.Request.Form;

HttpRequest.Params Property

HttpRequest。参数属性