【问题标题】:An unhandled exception occurred while processing the request. ArgumentException: Keyword not supported: 'service'处理请求时发生未处理的异常。 ArgumentException:不支持关键字:“服务”
【发布时间】:2020-12-03 08:50:18
【问题描述】:

我有一个 asp.net 核心 MVC 应用程序,在搭建脚手架后出现错误。

我的连接字符串如下appsettings.json

"ConnectionStrings": {
    "MyNewDatabase": "data source=.; initial catalog=MyNewDb; integrated security=true"
  }

而我遇到的错误:

> ArgumentException: Keyword not supported: 'service'.

我把它带到Startup.cs 的评论行,因为如果我不把它带到评论行,它会在这里出错

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

【问题讨论】:

  • 需要在你的启动文件中看到一些代码。您使用的是哪个版本的 .net core?
  • 我使用的是3.1.0版本的.net core

标签: asp.net-core model-view-controller appsettings


【解决方案1】:

我在Startup.cs改了下面的代码

> app.UseEndpoints(endpoints =>
>             {
>                 endpoints.MapControllerRoute(
>                     name: "default",
>                     pattern: "{controller=Home}/{action=Index}/{id?}");
>             });

我在AppDbContext.cs中添加了以下代码

optionsBuilder.UseSqlServer(@"data source=.; initial catalog=MyNewDb; integrated security=true");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-20
    • 2021-02-20
    • 2020-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多