繁体   English   中英

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

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

我正在尝试在本地 IIS 中托管 ASP.NET Core 2.0 WebApplication,但每次我都会收到以下错误:值不能为空。 参数名称:名称

在此处输入图片说明

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/"
    }
}
}

程序类看起来像这样:

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

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

启动类如下所示:

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" });
        });
    }
}

到目前为止我尝试了什么?

  • 我在解决方案中搜索了所有名为“name”的参数。 但我找不到任何可能是空的。
  • 如果我在 IIS express 中托管网站,那么它就可以工作。

问题似乎不在代码中。 它也是一个标准的 asp.net core 2.0 web 应用程序。 我没有触及代码本身。 我只尝试在 IIS 中托管网站。

有人可以帮助我吗?

我现在已经多次遇到同样的问题。 最初我教我以某种方式搞砸了一些东西,因为我第一次启动应用程序一切正常,但是在重新启动后“值不能为空。参数名称:名称”错误再次出现。 在对 IIS 进行了更多试验后,我发现创建应用程序并将其注册到具有完全相同规范的新应用程序池(iisreset 允许)可以解决此问题。 缺点是只要出现此错误,您就必须执行此操作。 这样做一次后,只需在我现在拥有的两个池之间切换,iisreset 就足够了。 希望有帮助!

我有同样的问题。 我花了半天时间尝试我能想到的所有可能的事情。

最后,我想到了

这是appsettings.json嵌套的问题

我不得不从 json 文件中删除一个额外的}

由于我在这里看不到您的appsetting.json文件,这也可能是您的情况的问题。 希望这会有所帮助。

我在进行调试 (F5) 时遇到了同样的问题。

解决了如下:

  1. 将您的 IIS 站点应用程序池设置为 DefaultAppPool
  2. 运行 (F5)
  3. 恢复到实际的应用程序池

就我而言,问题是关于“uriString”。 我不知道为什么,但关闭 Visual Studio 并打开解决了这个问题。 我希望它可以帮助某人。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM