小编MVC*_*MVC的帖子

如何在.NET MVC中获取用户当前访问国家/地区的位置?

我经历了这么多文件,但对我来说没什么用.我已经关注 了一个链接

我想通过IP地址获取当前用户的位置.但是,我ipAddress总是显示 null然后::1.我不知道我做错了什么.

任何人都可以帮我解决这个问题.

模型

   public class LocationModel
    {
        public string IP { get; set; }
        public string Country_Code { get; set; }           

    }
Run Code Online (Sandbox Code Playgroud)

调节器

public class HomeController : Controller
{
    // GET: Home
    public ActionResult Index()
    {
        string ipAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
        if (string.IsNullOrEmpty(ipAddress))
        {
            ipAddress = Request.ServerVariables["REMOTE_ADDR"];
        }
        LocationModel location = new LocationModel();
        string url = string.Format("http://freegeoip.net/json/{0}", ipAddress);
        using (WebClient client = new WebClient())
        {
            string json = client.DownloadString(url);
            location = new JavaScriptSerializer().Deserialize<LocationModel>(json); …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc

6
推荐指数
1
解决办法
1239
查看次数

我的 WPF 应用程序的当前上下文中不存在名称“InitializeComponent”

我最近将 .NET Framework 4.8 WPF 应用程序转换为 .NET5。当我编译应用程序时,出现以下错误

当前上下文中不存在名称“InitializeComponent”

我点击了这个链接,但帮不了我太多。

我检查了文件命名*.xaml空间*.cs

<Window x:Class="Cl.Wpf.MessageWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        SizeToContent = "WidthAndHeight"
        Title="MessageWindow" >
Run Code Online (Sandbox Code Playgroud)

还检查了.cs文件

namespace Cl.Wpf
{
    public partial class MessageWindow : Window
    {                     

        public MessageWindow()
        {
            InitializeComponent();
             .....
        }
Run Code Online (Sandbox Code Playgroud)

我的*.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net5.0-windows</TargetFramework>
    <OutputType>Library</OutputType>
    <RootNamespace>Cl.Wpf</RootNamespace>
    <Deterministic>false</Deterministic>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    <UseWPF>true</UseWPF>
    <ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers" Version="0.2.241603">
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
  </ItemGroup>
  <ItemGroup>
    <Compile Update="Properties\Settings.Designer.cs">
      <DesignTimeSharedInput>True</DesignTimeSharedInput>
      <AutoGen>True</AutoGen>
      <DependentUpon>Settings.settings</DependentUpon>
    </Compile>
  </ItemGroup>
  <ItemGroup>
    <None Update="Properties\Settings.settings">
      <Generator>SettingsSingleFileGenerator</Generator>
      <LastGenOutput>Settings.Designer.cs</LastGenOutput>
    </None>
  </ItemGroup>
</Project> …
Run Code Online (Sandbox Code Playgroud)

c# wpf visual-studio-2019

2
推荐指数
1
解决办法
607
查看次数

标签 统计

asp.net-mvc ×1

c# ×1

visual-studio-2019 ×1

wpf ×1