简体   繁体   中英

Unable to connect to web server IIS Express - ASP.NET CORE

My team has developed a asp.net core application in a windows vm on their macbook. I have a windows machine so, I was asked to update the App URL and Launch browser from localhost to my windows IP address . However, when I try to run the application it throws error and says 'Unable to connect to web server IIS Express'.

I've tried to run visual studio as administrator but still the error doesn't seems to go away. I'm attaching the screenshot for the reference. I would appreciate any help thank you.

在此处输入图像描述

By the way here's how my program.cs file look like.

    public class Program
    {
        /// <summary>
        /// Thread Main.
        /// </summary>
        /// <param name="args">Command Line args.</param>
        public static void Main(string[] args)
        {
            // Configuration builder to load ASPNETCORE env variables
            var config = new ConfigurationBuilder()
                .SetBasePath(Directory.GetCurrentDirectory())
                .AddEnvironmentVariables(prefix: "ASPNETCORE_")
                .Build();

            // WebHost Configuration
            // var host = WebHost.CreateDefaultBuilder(args)

            var host = MfHostBuilder.CreateHostBuilder(args).UseConfiguration(config)
               // .UseUrls("http://0.0.0.0:7785")
                .UseStartup<Startup>()
                //.UseKestrel()
                .Build();

            // Start and run the host.
            host.Run();
        }
    }
}

and here's my startup.cs file looks like.

public class Startup : IntegrationService
{
    public override void ConfigureServices(IServiceCollection services)
    {
        services.AddTransient<GenetecServerControllerOptions>();
        services.ConfigureOptions<ConfigureGenetecServerControllerOptions>();
        services.AddGenetec();
        services.AddSingleton<ServerProcessorOptions>();
        services.ConfigureOptions<ConfigureServerProcessorOptions>();
        base.ConfigureServices(services);
    }
}

You need to add IIS integration into your app, this will configure what is required for IIS: This is what I have and use in my Program.cs

return Host.CreateDefaultBuilder(args)
        .ConfigureWebHostDefaults(webBuilder => {
            webBuilder.UseContentRoot(Directory.GetCurrentDirectory());
            webBuilder.UseIISIntegration();
            webBuilder.UseStartup<Startup>();
        });

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