【问题标题】:vscode c# debugger missing routes in asp.net mvc core appvscode c#调试器在asp.net mvc核心应用程序中缺少路由
【发布时间】:2017-02-08 08:03:11
【问题描述】:

Visual Studio 代码的 c# 扩展中的调试器似乎改变了路由的工作方式;如果我使用 dotnet run 运行应用程序,一切都很好,但如果我使用调试器,某些路由会被忽略。

使用 dotnet run 响应

使用 c# 调试器响应(通过 app.Run(...);)

据我所知,配置中没有任何内容会影响这一点。

程序.cs

public class Program
{
    public static void Main(string[] args)
    {
        var host = new WebHostBuilder()
            .CaptureStartupErrors(true)
            .UseSetting("detailedErrors","true")
            .UseKestrel()
            .UseContentRoot(Directory.GetCurrentDirectory())
            .UseIISIntegration()
            .UseStartup<Startup>()
            .Build();

        host.Run();
    }
}

Startup.cs

public class Startup
{
    public IConfigurationRoot Configuration { get; }

    public Startup(IHostingEnvironment env)
    {
        var builder = new ConfigurationBuilder()
            .SetBasePath(env.ContentRootPath)
            .AddJsonFile("appsettings.json", true)
            .AddJsonFile($"appsettings.{env.EnvironmentName}.json", true)
            .AddEnvironmentVariables();

        Configuration = builder.Build();
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddEntityFrameworkSqlServer()       
            .AddDbContext<MyDbContext>(options =>                        
                options.UseSqlServer(Configuration.GetConnectionString("MyDbContext"))
                );

        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, ILoggerFactory loggerFactory)
    {
        loggerFactory
            .AddDebug()
            .AddConsole()
            .AddAzureWebAppDiagnostics();

        var logger = loggerFactory.CreateLogger<Startup>();

        logger.LogInformation(1, "Logging in Configure");
        logger.LogInformation(1, $"ConnectionString: {Configuration.GetConnectionString("MyDbContext")}");

        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        app.UseStaticFiles();    

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

        app.Run(async context => {
            await context.Response.WriteAsync($"Hello World:  The current environment is {env.EnvironmentName}, the current value is {Configuration["MyEnvironment"]}");
        });
    }
}

launch.json

    {
    "version": "0.2.0",
    "configurations": [
        {
        "name": ".NET Core Launch (web)",
        "type": "coreclr",
        "request": "launch",
        "preLaunchTask": "build",
        "program": "${workspaceRoot}\\src\\web\\bin\\Debug\\netcoreapp1.0\\web.dll",
        "args": [],
        "cwd": "${workspaceRoot}\\src\\web",
        "stopAtEntry": false,
        "internalConsoleOptions": "openOnSessionStart",
        "launchBrowser": {
            "enabled": true,
            "args": "${auto-detect-url}",
            "windows": {
                "command": "cmd.exe",
                "args": "/C start ${auto-detect-url}"
                },
            "osx": {
                "command": "open"
                },
            "linux": {
                "command": "xdg-open"
                }
            },
        "env": {
            "ASPNETCORE_ENVIRONMENT": "Development"
            },
        "sourceFileMap": {
            "/Views": "${workspaceRoot}/Views"
            }
        },
        {
        "name": ".NET Core Attach",
        "type": "coreclr",
        "request": "attach",
        "processId": "${command.pickProcess}"
        }]
    }

任何帮助表示赞赏。

【问题讨论】:

    标签: c# debugging visual-studio-code asp.net-core-mvc


    【解决方案1】:

    问题在于指定要调试的文件的 launch.json。在生成 launch.json 后,我已将项目更改为目标 1.1,并且它仍在指定 1.0 dll。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-07
      • 2016-08-03
      • 1970-01-01
      • 2012-11-20
      • 2018-08-09
      • 2019-10-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多