简体   繁体   English

命名空间“System.Web”中不存在类型或命名空间名称“UI”(您是否缺少程序集引用?)

[英]The type or namespace name 'UI' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)

I have asp.net core 2.2 project.我有asp.net core 2.2项目。 I want to use System.Web in my project but when i try to use this in my controller so it says like this我想在我的项目中使用System.Web ,但是当我尝试在我的控制器中使用它时,它是这样说的

The type or namespace name 'UI' does not exist in the namespace 'System.Web' (are you missing an assembly reference?) [D:\\Projects\\analytics\\analytics.csproj]命名空间“System.Web”中不存在类型或命名空间名称“UI”(您是否缺少程序集引用?)[D:\\Projects\\analytics\\analytics.csproj]

I have project.csproj file like this我有这样的 project.csproj 文件

<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
  <TargetFramework>netcoreapp2.2</TargetFramework>
  <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
</PropertyGroup>

<ItemGroup>
  <PackageReference Include="IpGeoLocation.IpGeoLocation" Version="1.0.5" />
  <PackageReference Include="Microsoft.AspNetCore.App" />
  <PackageReference Include="System.Web" />
  <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" 
  />
  <PackageReference Include="MongoDB.Driver" Version="2.7.3" PrivateAssets="All" />
  <PackageReference Include="MongoDB.Driver.Core" Version="2.7.3" PrivateAssets="All" />
  <PackageReference Include="MongoDB.Bson" Version="2.7.3" PrivateAssets="All" />
</ItemGroup>

</Project>

I am using System.Web because i am implementing third party plugin ipinfo to get user's location based on ip address.我使用System.Web是因为我正在实施第三方插件ipinfo以根据ip地址获取用户的位置。 So in my controller my function is like所以在我的控制器中我的功能就像

string ipInfoBaseUrl = "http://ipinfo.io/";
string userIpAddress = "66.54.123.13";
string ipUrl = ipInfoBaseUrl + userIpAddress;
string ipResponse = IPRequestHelper(ipUrl);
return ipResponse;

My helper function is like我的助手功能就像

public string IPRequestHelper(string url)
{
        string checkURL = url;
        HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url);

        HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();

        StreamReader responseStream = new StreamReader(objResponse.GetResponseStream());

        string responseRead = responseStream.ReadToEnd();

        responseRead = responseRead.Replace("\n", String.Empty);
        responseStream.Close();
        responseStream.Dispose();

        return responseRead;
}

I am using Visual Studio Code.我正在使用 Visual Studio 代码。 How can i get rid of this error?我怎样才能摆脱这个错误?

That namespace belongs to ASP.NET Web Pages and isn't part of .NET Core, hence you cannot use it in an ASP.NET Core project.该命名空间属于 ASP.NET 网页,而不是 .NET Core 的一部分,因此您不能在 ASP.NET Core 项目中使用它。

Your options are ASP.NET Core razor pages, or Blazor.您可以选择 ASP.NET Core razor 页面或 Blazor。

If you're using a 3rd party library that depends on legacy .NET Framework (non-Core), you may want to switch-back and use classic ASP.NET instead.如果您使用的是依赖于旧版 .NET Framework(非核心)的 3rd 方库,您可能需要切换回并改用经典的 ASP.NET。

For IP address in the .NET Framework, use the System.Net.IPAddress class对于 .NET Framework 中的 IP 地址,请使用System.Net.IPAddress

Looks like the IpGeoLocation.IpGeoLocation package has no dependencies but on JSON.NET, so you should probably be able to use it from ASP.NET Core.看起来IpGeoLocation.IpGeoLocation包没有依赖项但依赖于 JSON.NET,所以你应该可以从 ASP.NET Core 使用它。

Update更新

Replace that code with the following:将该代码替换为以下内容:

public async Task<string> GetIpGeoLocationAsync(string url)
{
  using (var cl = new HttpClient())
    return await cl.GetStringAsync(url);
}

Also, consider using IHttpClientFactory instead.另外,请考虑改用IHttpClientFactory

暂无
暂无

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

相关问题 命名空间“System.Web”中不存在类型或命名空间名称“Mvc”(您是否缺少程序集引用?) - The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?) 命名空间“System.Web”中不存在类型或命名空间名称“Mvc”(您是否缺少程序集引用?)Kentico - The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?) Kentico CS0234:类型或名称空间名称“ WebPages”在名称空间“ System.Web”中不存在(您是否缺少程序集引用?) - CS0234: The type or namespace name 'WebPages' does not exist in the namespace 'System.Web' (are you missing an assembly reference?) 命名空间“System.Web.UI”中不存在类型或命名空间名称“DataVisualization”(您是否缺少程序集引用?) - The type or namespace name 'DataVisualization' does not exist in the namespace 'System.Web.UI' (are you missing an assembly reference?) 类型或名称空间名称在名称空间中不存在“是否缺少程序集引用?” - The type or namespace name does not exist in the namespace ''are you missing an assembly reference ?" 命名空间中不存在类型或命名空间名称(您是否缺少程序集引用?) - The type or namespace name does not exist in the namespace (are you missing an assembly reference?) 类型或名称空间名称“ Routing”在名称空间“ System.Web”中不存在 - The type or namespace name 'Routing' does not exist in the namespace 'System.Web' 命名空间“System.Web”中不存在类型或命名空间名称“优化” - The type or namespace name 'Optimization' does not exist in the namespace 'System.Web' 类型或名称空间名称“ Http”在名称空间“ System.Web”中不存在 - The type or namespace name 'Http' does not exist in the namespace 'System.Web' CS0234:类型或名称空间名称“ Description”在名称空间“ System.Web.Http”中不存在(您是否缺少程序集引用?) - CS0234: The type or namespace name 'Description' does not exist in the namespace 'System.Web.Http' (are you missing an assembly reference?)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM