【问题标题】:How to change the default browser for debugging in Visual Studio 2017?如何更改 Visual Studio 2017 中调试的默认浏览器?
【发布时间】:2018-07-19 13:29:21
【问题描述】:

我正在开发一个使用 Topshelf 作为服务托管的 ASP.NET Core Web API 项目。当我从调试器启动服务时,Swagger 页面出现在 Internet Explorer 中。我该如何更改才能使用 Chrome 启动它?

【问题讨论】:

标签: asp.net-core visual-studio-2017 windows-services


【解决方案1】:

从开始调试按钮,单击小箭头,然后执行以下操作:

【讨论】:

  • 我的 WebApi 项目是一个控制台应用程序,它使用 Topshelf 作为 Windows 服务进行冲洗,所以可能是因为这个原因,我没有看到 IISExpress 菜单
【解决方案2】:

在这种情况下,从控制面板中选择默认浏览器。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="WebSiteBinding" value="http://localhost:63037"/>
<add key="Environment" value="LOCAL"/>
<add key="ServiceName" value="Debug"/>
<add key="ServiceDisplayName" value="Debug"/>
</appSettings>
</configuration>

class ApiService
{
    private string _url;
    private IWebHost _host;

    public void Start(string[] args)
    {
        _url = ConfigurationManager.AppSettings["WebSiteBinding"];

        _host = BuildWebHost(args);
        _host.Start();

#if DEBUG
        System.Diagnostics.Process.Start(_url);
#endif
    }

    public void Stop()
    {
        _host.Dispose();
    }

    public IWebHost BuildWebHost(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>()
            .UseNLog()
            .UseHttpSys(options =>
            {
                options.Authentication.Schemes = AuthenticationSchemes.NTLM;
                options.Authentication.AllowAnonymous = true;
                options.UrlPrefixes.Add(_url);
            })
            .Build();
}

【讨论】:

    猜你喜欢
    • 2018-08-17
    • 1970-01-01
    • 1970-01-01
    • 2017-07-03
    • 2011-01-27
    • 1970-01-01
    • 1970-01-01
    • 2018-09-07
    • 2018-04-28
    相关资源
    最近更新 更多