更改端口号后无法在Visual Studio中调试? [英] Cannot debug in Visual Studio after changing the port number?

查看:308
本文介绍了更改端口号后无法在Visual Studio中调试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加了 .UseUrls( http:// *:5000)行,以允许其他主机的客户端访问Web api。

I added the line .UseUrls("http://*:5000") to enable clients from other hosts accessing the web api.

    public static void Main(string[] args)
    {
        var host = new WebHostBuilder()
            .UseKestrel()
            .UseContentRoot(Directory.GetCurrentDirectory())
            .UseIISIntegration()
            .UseStartup<Startup>()
            .UseUrls("http://*:5000") // Added
            .Build();

        host.Run();
    }

但是,使用浏览器访问 localhost:5000 / api / Test 收到 HTTP / 1.1 400 Bad Request 的错误?应该只为生产而编译 .UseUrls()吗?

However, using browser to access localhost:5000/api/Test got the error of HTTP/1.1 400 Bad Request? Should the .UseUrls() be only compiled for production?


HTTP/1.1 400 Bad Request
Date: Mon, 08 Aug 2016 21:42:30 GMT
Content-Length: 0
Server: Kestrel

在测试时,将从Visual Studio输出窗口复制以下消息。

The following messages are copied from Visual studio Output window when testing.


Microsoft.AspNetCore.Hosting.Internal .WebHost:信息:请求启动HTTP / 1.1 GET http:// localhost:5000 / api / Test

Microsoft.AspNetCore.Server.IISIntegration.IISMiddleware:错误:'MS-ASPNETCORE-TOKEN'与预期的配对令牌'9bca37f2-7eda-4517-9f8f-60b6cc05cf01 ',请求被拒绝。

Microsoft.AspNetCore.Server.IISIntegration.IISMiddleware:Error: 'MS-ASPNETCORE-TOKEN' does not match the expected pairing token '9bca37f2-7eda-4517-9f8f-60b6cc05cf01', request rejected.

Microsoft.AspNetCore.Hosting.Internal.WebHost:信息:请求在8.5976毫秒内完成400

Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request finished in 8.5976ms 400


推荐答案

您应先调用 .UseUrls()和/或 .UseConfig() d然后 .UseIISIntegration()

You should call first .UseUrls() and/or .UseConfig() and then .UseIISIntegration().

在IIS / IISExpress下正常运行时,最终会有2个进程。 IIS在所需的端口上侦听,而Kestrel在另一个端口上侦听。您的请求应该转到IIS,然后转发到Kestrel(带有 MS-ASPNETCORE-TOKEN )。

When running ok under IIS/IISExpress, you end up with 2 processes. IIS listening on the desired port and Kestrel on another one. Your requests should go to IIS and then it is forwarded to Kestrel (with the MS-ASPNETCORE-TOKEN).

.UseIISIntegration()的调用将隐藏此映射。它实际上会更改应用程序中的端口,并在所需的端口上设置 IIS 。但是,如果您以不正确的顺序调用这两种方法,则会中断。

The call to .UseIISIntegration() hides this mapping. It actually changes the port in your app and sets IIS on the desired port. But it breaks if you call both methods in incorrect order.

您收到此错误消息是因为Kestrel预期在 IIS ,并收到直接请求。并且它注意到,由于 IIS 不在那里,因此无法注入 MS-ASPNETCORE-TOKEN 标头。

You are getting this error message because Kestrel expected to run behind IIS, and received a direct request. And it noticed that because IIS was not there to inject the MS-ASPNETCORE-TOKEN header.

问题记录了该问题并可能解决在以后的版本中。

This issue documents the issue and may solve it in future releases.

这篇关于更改端口号后无法在Visual Studio中调试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆