简体   繁体   English

ASP.NET Core 2.0 值不能为空。 参数名称:名称

[英]ASP.NET Core 2.0 Value cannot be null. Parameter name: Name

I'm trying to host a ASP.NET Core 2.0 WebApplication in local IIS, but evertime i get the following error: Value cannot be null.我正在尝试在本地 IIS 中托管 ASP.NET Core 2.0 WebApplication,但每次我都会收到以下错误:值不能为空。 Parameter name: name参数名称:名称

在此处输入图片说明

The launchSettings.json file looks like this: launchSettings.json 文件如下所示:

{
"iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iis": {
        "applicationUrl": "http://localhost/zoyotravel",
        "sslPort": 0
    },
    "iisExpress": {
        "applicationUrl": "http://localhost:56472/",
        "sslPort": 0
    }
},
"profiles": {
    "IIS Express": {
        "commandName": "IISExpress",
        "launchBrowser": true,
        "environmentVariables": {
            "ASPNETCORE_ENVIRONMENT": "Development"
        }
    },
    "Zoyo Travel": {
        "commandName": "IIS",
        "launchBrowser": true,
        "environmentVariables": {
            "ASPNETCORE_ENVIRONMENT": "Development"
        },
        "applicationUrl": "http://localhost:56473/"
    }
}
}

The program class looks liks this:程序类看起来像这样:

public class Program
{
    public static void Main(string[] args)
    {
        BuildWebHost(args).Run();
    }

    public static IWebHost BuildWebHost(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>()
            .Build();
}

The startup class looks like this:启动类如下所示:

public class Startup
{
    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc();
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
            app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
            {
                HotModuleReplacement = true
            });
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
        }

        app.UseStaticFiles();

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");

            routes.MapSpaFallbackRoute(
                name: "spa-fallback",
                defaults: new { controller = "Home", action = "Index" });
        });
    }
}

What have I tried so far?到目前为止我尝试了什么?

  • I have searched for all the parameters called "name" in the solution.我在解决方案中搜索了所有名为“name”的参数。 But I could not find anything that could be empty.但我找不到任何可能是空的。
  • If I host the website in IIS express then it works.如果我在 IIS express 中托管网站,那么它就可以工作。

The problem does not appear to be in the code.问题似乎不在代码中。 It is also a standard asp.net core 2.0 web application.它也是一个标准的 asp.net core 2.0 web 应用程序。 I did not touch the code itself.我没有触及代码本身。 I have only tried to host the website in IIS.我只尝试在 IIS 中托管网站。

Can somebody help me?有人可以帮助我吗?

I have encountered the same issue several times now.我现在已经多次遇到同样的问题。 Initially I taught I was somehow messing something up because first time I started the app everything worked, but after a restart that "Value cannot be null. Parameter name: name" error appeared again.最初我教我以某种方式搞砸了一些东西,因为我第一次启动应用程序一切正常,但是在重新启动后“值不能为空。参数名称:名称”错误再次出现。 After some more experimenting with IIS I've discovered that creating and registering your app to a new application pool with the exact same specs, fallowed by iisreset solves this problem.在对 IIS 进行了更多试验后,我发现创建应用程序并将其注册到具有完全相同规范的新应用程序池(iisreset 允许)可以解决此问题。 The downside is that you have to do this whenever this error appears.缺点是只要出现此错误,您就必须执行此操作。 After doing this once just switching between the two pools I now had and iisreset was enough.这样做一次后,只需在我现在拥有的两个池之间切换,iisreset 就足够了。 Hope it helps!希望有帮助!

I had the same issue.我有同样的问题。 I spent half a day trying every possible thing that I could think of.我花了半天时间尝试我能想到的所有可能的事情。

Finally, I figured that最后,我想到了

it was an issue with appsettings.json nesting .这是appsettings.json嵌套的问题

I had to remove an extra } from the json file .我不得不从 json 文件中删除一个额外的}

Since I cannot see your appsetting.json file here, it may be the problem in your case as well.由于我在这里看不到您的appsetting.json文件,这也可能是您的情况的问题。 Hope this helps.希望这会有所帮助。

I faced the same issue while doing a Debug (F5).我在进行调试 (F5) 时遇到了同样的问题。

Solved it as follows:解决了如下:

  1. Set your IIS Site App Pool to DefaultAppPool将您的 IIS 站点应用程序池设置为 DefaultAppPool
  2. Run (F5)运行 (F5)
  3. Revert to the actual app pool恢复到实际的应用程序池

In my case issue was about 'uriString'.就我而言,问题是关于“uriString”。 I don't know why but closing visual studio and opening fixed the issue.我不知道为什么,但关闭 Visual Studio 并打开解决了这个问题。 I hope it helps someone.我希望它可以帮助某人。

暂无
暂无

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

相关问题 Asp.Net Core 2.0 ArgumentNullException:值不能为null。 参数名称:connectionString - Asp.Net Core 2.0 ArgumentNullException: Value cannot be null. Parameter name: connectionString 值不能为空。 参数名称:Asp.net中的源 - Value cannot be null. Parameter name: source in Asp.net 错误:'值不能是 null。 参数名称:上下文'ASP.NET MVC - Error: 'Value cannot be null. Parameter name: context' ASP.NET MVC 值不能为空。 参数名称:项目(在下拉列表中)ASP.NET MVC5 - Value cannot be null. Parameter name: items (in Dropdown List) ASP.NET MVC5 MVC3 asp.net错误:值不能为null。参数名称:下拉列表中的项目 - MVC3 asp.net error: Value cannot be null. Parameter name: items on dropdownlist ASP.NET Core 5 MVC:ArgumentNullException:值不能为空。 (参数“项目”) - ASP.NET Core 5 MVC: ArgumentNullException: Value cannot be null. (Parameter 'items') 值不能是 null。 (参数“主体”)[身份][ASP.net核心] - Value cannot be null. (Parameter 'principal') [ Identity ] [ ASP.net core ] 单元测试 ASP.NET 核心 3.1 MVC controller - 值不能是 null。 (参数“提供者”) - Unit testing ASP.NET Core 3.1 MVC controller - value cannot be null. (Parameter 'provider') 值不能是 null。 ASP.NET Core 3..0 中的(参数'key') - Value cannot be null. (Parameter 'key') in ASP.NET Core 3..0 ASP.NET 核心 - 值不能是 null。 当前用户配置文件中的(参数“s”) - ASP.NET Core - Value cannot be null. (Parameter 's') in Current User Profile
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM