简体   繁体   中英

Stuck figuring out the initialization sequence of ASP.NET Core 2.1

This is a problem that has been hard for me to figure out. I wanted to make a micro-service out of an ASP.NET Core Application. I've been able to deploy .NET Core with Kestrel as an edge server and behind a proxy like Nginx. This seems semi-inconsequential, so haven't spent forever on it, but I can't figure out how to land on a different url other than root when my application starts up. In other words, I've changed the default routing, this is an mvc application, and I added a prefix like this into Startup.cs :

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

In production, not a problem, doesn't matter what the default route is, but when I develop in VisualStudio and hit play, I get the blank browser because its pointing to "/" instead of "/SqlServer". Any idea how to fix this?

Also relevant is Program.cs :

public class Program
{
    public static void Main(string[] args)
    {
        CreateWebHostBuilder(args).Build().Run();
    }
    public static IWebHostBuilder CreateWebHostBuilder(string[] args)
    {
        return WebHost.CreateDefaultBuilder(args)
            .UseKestrel(options =>
            {
                options.Limits.MaxConcurrentConnections = 100;
                options.Limits.MaxConcurrentUpgradedConnections = 100;
                options.Limits.MaxRequestBodySize = 10 * 1024;
                options.Limits.MinRequestBodyDataRate = new MinDataRate(bytesPerSecond: 100, gracePeriod: TimeSpan.FromSeconds(10));
                options.Limits.MinResponseDataRate = new MinDataRate(bytesPerSecond: 100, gracePeriod: TimeSpan.FromSeconds(10));
                options.Listen(IPAddress.Any, 5000);
                options.Listen(IPAddress.Any, 5001, listenOptions =>
                {
                    listenOptions.UseHttps("/Users/ryandines/DevelopmentCode/ExampleProject/testCert.pfx", "notMyPassword");
                });
            }).UseStartup<Startup>();
    }
}

There's 2 ways of changing this setting.

Using Visual Studio

  1. Right click on the project, select "Properties"
  2. Select "Debug" tab
  3. Next to the "Launch browser" checkbox, enter a URL that you want to start when the app runs.

Edit settings manually

Manually add a launchUrl property to the profile, for example:

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:1234/",
      "sslPort": 0
    }
  },
  "profiles": {
    "<name of profile>": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "http://localhost:1234/cheese",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Local"
      }
    },
    //etc...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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