Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 此本地主机页可以’;找不到。找不到网址“的网页”&引用;_C#_Asp.net Core_Asp.net Core Webapi - Fatal编程技术网

C# 此本地主机页可以’;找不到。找不到网址“的网页”&引用;

C# 此本地主机页可以’;找不到。找不到网址“的网页”&引用;,c#,asp.net-core,asp.net-core-webapi,C#,Asp.net Core,Asp.net Core Webapi,我正在尝试创建web API,但当我执行该程序时,会弹出以下消息: 找不到此本地主机页。找不到网址“TheAddress”的网页 我正在学习,所以我不确定我要发布的代码是否有帮助(这是我写的所有代码) 控制器: namespace ApiPractice.Controllers { [Route("api/[controller]")] //puts the endpoint communication in "Auto" (It takes it from AutoController

我正在尝试创建web API,但当我执行该程序时,会弹出以下消息: 找不到此本地主机页。找不到网址“TheAddress”的网页

我正在学习,所以我不确定我要发布的代码是否有帮助(这是我写的所有代码)

控制器:

namespace ApiPractice.Controllers
{
    [Route("api/[controller]")] //puts the endpoint communication in "Auto" (It takes it from AutoController)
    [ApiController] //automate code 
    public class AutoController : ControllerBase
    {
        private readonly AplicationDbContext context;
        public AutoController(AplicationDbContext context)
        {
            this.context = context;
        }

        [HttpGet]
        public ActionResult<IEnumerable<Usuarios>> Get()
        {
            return context.Users.ToList();
        }
    }
}
上下文

namespace ApiPractice.Context
{
    public class AplicationDbContext: DbContext
    {
        public AplicationDbContext (DbContextOptions<AplicationDbContext> options) : base(options) //does some weird shit, but it works.
        { }

        public DbSet<Usuarios> Users { get; set; }  //Somehow the database creates a table based on Users.
    }
}
名称空间apipracture.Context
{
公共类应用程序DbContext:DbContext
{
publicplicationdbcontext(DbContextOptions):base(options)//做了一些奇怪的事情,但它能工作。
{ }
public DbSet Users{get;set;}//数据库以某种方式基于用户创建一个表。
}
}
Startup.cs,配置服务方法:

public void ConfigureServices(IServiceCollection services)
{
    //No idea what this does, but I needed for the creation of the table
    services.AddDbContext<AplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); 

    services.AddControllers();
}
public void配置服务(IServiceCollection服务)
{
//不知道这是做什么的,但我需要创建表
services.AddDbContext(options=>options.UseSqlServer(Configuration.GetConnectionString(“DefaultConnection”));
services.AddControllers();
}
我还更改了api/autores项目属性中“调试”菜单上的“启动浏览器”属性。。。不知道我为什么要这么做


就这些,如果您还需要什么,我会在看到您的请求后立即提供给您,非常感谢您抽出时间,希望大家过得愉快。(:

正如@mason指出的那样,我使用了错误的URL。

你浏览的地址是什么?xxxxx=一个五位数的数字,我不发布它,因为我不确定我是否能做到。为什么在你的URL中使用“autores”?它应该是“auto”,因为你的控制器是“AutoController”@mason好的,我只是复制了一个家伙在视频中所做的事情,没有意识到我在课堂上没有使用相同的名字哈哈哈,现在可以了,非常感谢你,顺便说一句,如果你想要声誉,你可以回答这个问题。
public void ConfigureServices(IServiceCollection services)
{
    //No idea what this does, but I needed for the creation of the table
    services.AddDbContext<AplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); 

    services.AddControllers();
}