I'm using .NET Core 2.0.2 to create an ASP.NET webapp in C#.
Everytime I use Request.Url
in my controllers, dotnet run
outputs an error:
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
The same thing happens with Request.Params
. Even though the .NET documentation says there is a getter for the Params
property.
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
.
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
?
The stuff you used to get from generic request params is accessible in specific properties of Request
like Query
, Cookies
, Form
etc.
If you are trying to access a querystring item value, you may use the Request.Query
property.
var v = Request.Query["oauth_verifier"];
You can use the TryGetValue
method on the collection to get the value if it exist.
if (Request.Query.TryGetValue("oauth_verifier",out StringValues val))
{
var theValue = val[0];
var orUseThis = val.ToString();
// Use theValue as needed
}
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...
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With