在“ Windows Server 2008 R2”上以相同的域名但不同的端口(分别为:81和:80)托管ASP.Net Core 2.1 Webapi和Angular 6 Webapp;不在同一文件夹中。
根据this article,当Websocket不可用时,SSE是(标准)备用,这是预期的,因为服务器不支持IIS 8.0(server is IIS 7.5)中引入的Websocket。
在开发中,一切都完美运行。但是,发布后,浏览器控制台将在15秒(可能是默认的“ HandshakeTimeout”时间)后报告以下内容。
{
"id": "21.70,104.88",
"vt1dailyforecast": {
"validDate": ["2018-08-13T07:00:00+0700", "2018-08-14T07:00:00+0700", "2018-08-15T07:00:00+0700", "2018-08-16T07:00:00+0700", "2018-08-17T07:00:00+0700", "2018-08-18T07:00:00+0700", "2018-08-19T07:00:00+0700", "2018-08-20T07:00:00+0700", "2018-08-21T07:00:00+0700", "2018-08-22T07:00:00+0700", "2018-08-23T07:00:00+0700", "2018-08-24T07:00:00+0700", "2018-08-25T07:00:00+0700", "2018-08-26T07:00:00+0700", "2018-08-27T07:00:00+0700"],
"sunrise": ["2018-08-13T05:37:18+0700", "2018-08-14T05:37:39+0700", "2018-08-15T05:38:00+0700", "2018-08-16T05:38:21+0700", "2018-08-17T05:38:41+0700", "2018-08-18T05:39:01+0700", "2018-08-19T05:39:21+0700", "2018-08-20T05:39:40+0700", "2018-08-21T05:40:00+0700", "2018-08-22T05:40:19+0700", "2018-08-23T05:40:38+0700", "2018-08-24T05:40:56+0700", "2018-08-25T05:41:14+0700", "2018-08-26T05:41:33+0700", "2018-08-27T05:41:51+0700"],
"sunset": ["2018-08-13T18:33:04+0700", "2018-08-14T18:32:21+0700", "2018-08-15T18:31:38+0700", "2018-08-16T18:30:53+0700", "2018-08-17T18:30:07+0700", "2018-08-18T18:29:21+0700", "2018-08-19T18:28:34+0700", "2018-08-20T18:27:46+0700", "2018-08-21T18:26:58+0700", "2018-08-22T18:26:09+0700", "2018-08-23T18:25:19+0700", "2018-08-24T18:24:28+0700", "2018-08-25T18:23:37+0700", "2018-08-26T18:22:45+0700", "2018-08-27T18:21:53+0700"],
"moonIcon": ["WXC", "WXC", "WXC", "WXC", "WXC", "FQ", "WXG", "WXG", "WXG", "WXG", "WXG", "WXG", "WXG", "F", "F"],
"moonPhrase": ["Waxing Crescent", "Waxing Crescent", "Waxing Crescent", "Waxing Crescent", "Waxing Crescent", "First Quarter", "Waxing Gibbous", "Waxing Gibbous", "Waxing Gibbous", "Waxing Gibbous", "Waxing Gibbous", "Waxing Gibbous", "Waxing Gibbous", "Full Moon", "Full Moon"],
"moonrise": ["2018-08-13T07:20:15+0700", "2018-08-14T08:22:42+0700", "2018-08-15T09:21:39+0700", "2018-08-16T10:19:15+0700", "2018-08-17T11:14:22+0700", "2018-08-18T12:08:52+0700", "2018-08-19T13:01:55+0700", "2018-08-20T13:53:58+0700", "2018-08-21T14:44:56+0700", "2018-08-22T15:33:22+0700", "2018-08-23T16:20:28+0700", "2018-08-24T17:04:24+0700", "2018-08-25T17:46:06+0700", "2018-08-26T18:26:02+0700", "2018-08-27T19:03:39+0700"],
"moonset": ["2018-08-13T20:14:44+0700", "2018-08-14T20:58:09+0700", "2018-08-15T21:39:20+0700", "2018-08-16T22:20:10+0700", "2018-08-17T23:00:28+0700", "2018-08-18T23:41:40+0700", "", "2018-08-20T00:24:58+0700", "2018-08-21T01:09:26+0700", "2018-08-22T01:56:23+0700", "2018-08-23T02:45:13+0700", "2018-08-24T03:34:42+0700", "2018-08-25T04:25:49+0700", "2018-08-26T05:16:20+0700", "2018-08-27T06:07:39+0700"],
"dayOfWeek": ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday"],
"snowQpf": [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
"day": {
"dayPartName": ["Today", "Tomorrow", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday"],
"precipPct": [10, 10, 20, 100, 100, 80, 80, 60, 40, 30, 80, 80, 80, 60, 80],
"precipAmt": [0.0, 0.0, 0.0, 0.73, 0.73, 0.3, 0.13, 0.11, 0.05, 0.02, 0.13, 0.2, 0.27, 0.14, 0.17],
"precipType": ["rain", "rain", "rain", "rain", "rain", "rain", "rain", "rain", "rain", "rain", "rain", "rain", "rain", "rain", "rain"],
"temperature": [96, 97, 94, 87, 84, 87, 89, 90, 90, 89, 89, 89, 90, 89, 90],
"uvIndex": [10, 11, 11, 6, 8, 10, 11, 10, 10, 8, 8, 8, 8, 8, 8],
"uvDescription": ["Very High", "Extreme", "Extreme", "High", "Very High", "Very High", "Extreme", "Very High", "Very High", "Very High", "Very High", "Very High", "Very High", "Very High", "Very High"],
"icon": [30, 30, 30, 4, 4, 4, 4, 38, 38, 37, 4, 4, 4, 38, 4],
"iconExtended": [3000, 3000, 3000, 400, 400, 400, 400, 3800, 3800, 3700, 400, 400, 400, 3800, 400],
"phrase": ["Partly Cloudy", "Partly Cloudy", "Partly Cloudy", "Thunderstorms", "Thunderstorms", "Thunderstorms", "Thunderstorms", "Scattered Thunderstorms", "Scattered Thunderstorms", "Isolated Thunderstorms", "Thunderstorms", "Thunderstorms", "Thunderstorms", "Scattered Thunderstorms", "Thunderstorms"],
"narrative": ["Partly cloudy. High 96F. Winds light and variable.", "Partly cloudy. High 97F. Winds light and variable.", "Mostly cloudy skies early will become partly cloudy later in the day. High 94F. Winds light and variable.", "Thunderstorms likely. High 87F. Winds NW at 5 to 10 mph. Chance of rain 100%.", "Thunderstorms likely. High 84F. Winds NNE at 5 to 10 mph. Chance of rain 100%.", "Showers and thunderstorms. High 87F. Winds light and variable. Chance of rain 80%.", "Scattered thunderstorms in the morning, then mainly cloudy during the afternoon with thunderstorms likely. High 89F. Winds light and variable. Chance of rain 80%.", "Partly to mostly cloudy with a chance of thunderstorms. High near 90F. Winds light and variable. Chance of rain 60%.", "Scattered showers and thunderstorms, especially early in the day. High near 90F. Winds light and variable. Chance of rain 40%.", "Isolated thunderstorms in the morning, then mainly cloudy late. High 89F. Winds light and variable. Chance of rain 30%.", "Thunderstorms. High 89F. Winds light and variable. Chance of rain 80%.", "Thunderstorms likely. High 89F. Winds light and variable. Chance of rain 80%.", "Thunderstorms. High around 90F. Winds light and variable. Chance of rain 80%.", "Scattered thunderstorms. High 89F. Winds light and variable. Chance of rain 60%.", "Scattered thunderstorms in the morning becoming more widespread in the afternoon. High near 90F. Winds light and variable. Chance of rain 80%."],
"cloudPct": [36, 56, 61, 94, 85, 78, 67, 66, 71, 72, 79, 83, 82, 83, 85],
"windDirCompass": ["S", "NW", "NNW", "NW", "NNE", "N", "NNE", "ENE", "ENE", "ENE", "NE", "N", "NW", "NNW", "N"],
"windDirDegrees": [177, 318, 328, 318, 14, 1, 13, 73, 58, 58, 36, 357, 322, 337, 3],
"windSpeed": [5, 4, 4, 6, 6, 5, 4, 5, 4, 4, 4, 4, 4, 4, 4],
"humidityPct": [57, 64, 71, 82, 87, 81, 78, 78, 78, 80, 79, 79, 78, 77, 76],
"qualifier": [null, null, null, null, null, null, null, null, null, null, null, null, null, null, null],
"snowRange": ["", "", "", "", "", "", "", "", "", "", "", "", "", "", ""],
"thunderEnum": [0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
"thunderEnumPhrase": ["No thunder", "No thunder", "No thunder", "Thunder expected", "Thunder expected", "Thunder expected", "Thunder expected", "Thunder expected", "Thunder expected", "Thunder expected", "Thunder expected", "Thunder expected", "Thunder expected", "Thunder expected", "Thunder expected"]
},
"night": {
"dayPartName": ["Tonight", "Tomorrow night", "Wednesday night", "Thursday night", "Friday night", "Saturday night", "Sunday night", "Monday night", "Tuesday night", "Wednesday night", "Thursday night", "Friday night", "Saturday night", "Sunday night", "Monday night"],
"precipPct": [10, 20, 90, 100, 90, 80, 80, 80, 80, 80, 80, 80, 80, 40, 50],
"precipAmt": [0.0, 0.0, 0.37, 1.26, 0.79, 0.34, 0.31, 0.24, 0.25, 0.15, 0.14, 0.21, 0.25, 0.07, 0.12],
"precipType": ["rain", "rain", "rain", "rain", "rain", "rain", "rain", "rain", "rain", "rain", "rain", "rain", "rain", "rain", "rain"],
"temperature": [79, 79, 78, 77, 77, 77, 77, 78, 77, 77, 77, 77, 77, 78, 77],
"uvIndex": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"uvDescription": ["Low", "Low", "Low", "Low", "Low", "Low", "Low", "Low", "Low", "Low", "Low", "Low", "Low", "Low", "Low"],
"icon": [29, 29, 4, 12, 4, 4, 4, 4, 4, 4, 4, 4, 4, 47, 47],
"iconExtended": [2900, 2900, 400, 1240, 400, 400, 400, 400, 400, 400, 400, 400, 400, 3809, 3809],
"phrase": ["Partly Cloudy", "Partly Cloudy", "Thunderstorms", "Rain/Thunder", "Thunderstorms", "Thunderstorms", "Thunderstorms", "Thunderstorms", "Thunderstorms", "Thunderstorms", "Thunderstorms", "Thunderstorms", "Thunderstorms", "Scattered Thunderstorms", "Scattered Thunderstorms"],
"narrative": ["Partly cloudy skies. Low 79F. Winds light and variable.", "A few clouds. Low 79F. Winds light and variable.", "Thunderstorms likely. Low 78F. Winds light and variable. Chance of rain 90%.", "Showers and thundershowers in the evening, then cloudy with rain likely overnight. Low 77F. Winds N at 5 to 10 mph. Chance of rain 100%. 1 to 2 inches of rain expected.", "Showers and thunderstorms likely. Low 77F. Winds light and variable. Chance of rain 90%.", "Showers and thunderstorms likely. Low 77F. Winds light and variable. Chance of rain 80%.", "Showers and thunderstorms likely. Low 77F. Winds light and variable. Chance of rain 80%.", "Thunderstorms. Low 78F. Winds light and variable. Chance of rain 80%.", "Thunderstorms likely. Low 77F. Winds light and variable. Chance of rain 80%.", "Thunderstorms. Low 77F. Winds light and variable. Chance of rain 80%.", "Thunderstorms likely. Low 77F. Winds light and variable. Chance of rain 80%.", "Thunderstorms likely. Low 77F. Winds light and variable. Chance of rain 80%.", "Thunderstorms likely. Low 77F. Winds light and variable. Chance of rain 80%.", "Variably cloudy with scattered thunderstorms. Low 78F. Winds light and variable. Chance of rain 40%.", "Scattered thunderstorms. Low 77F. Winds light and variable. Chance of rain 50%."],
"cloudPct": [44, 54, 75, 99, 95, 84, 86, 84, 77, 84, 83, 89, 83, 89, 89],
"windDirCompass": ["WNW", "WNW", "NW", "N", "NNW", "NNW", "N", "NNE", "NNE", "N", "NNE", "N", "N", "NNW", "NNE"],
"windDirDegrees": [296, 301, 308, 1, 336, 345, 350, 27, 14, 9, 13, 0, 357, 348, 17],
"windSpeed": [4, 4, 4, 7, 4, 3, 3, 4, 3, 3, 3, 4, 4, 4, 3],
"humidityPct": [84, 83, 89, 93, 95, 93, 93, 92, 93, 95, 92, 92, 91, 89, 91],
"qualifier": [null, null, null, null, null, null, null, null, null, null, null, null, null, null, null],
"snowRange": ["", "", "", "", "", "", "", "", "", "", "", "", "", "", ""],
"thunderEnum": [0, 0, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
"thunderEnumPhrase": ["No thunder", "No thunder", "Thunder expected", "Thunder possible", "Thunder expected", "Thunder expected", "Thunder expected", "Thunder expected", "Thunder expected", "Thunder expected", "Thunder expected", "Thunder expected", "Thunder expected", "Thunder expected", "Thunder expected"]
}
}
}
Startup.cs当前的设置如下:
> Information: SSE connected to http://my.website.com:81/notify?id=kaSkcGUjcZD4ylJAC7B70A
> Error: Connection disconnected with error 'Error: Server returned handshake error: Handshake was canceled.'.
> Error: Not Found
SignalR集线器几乎为空(事件推送在其他地方处理):
public void ConfigureServices(IServiceCollection services)
{
services.AddSignalR();
services.AddMemoryCache();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddCors(o => {
o.AddPolicy("Limited", builder => builder
.WithOrigins("http://my.website.com") // .AllowAnyOrigin() also tested and worked
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials()
);
});
services.AddDbContext<DatabaseContext>(options => {
options.UseSqlServer(Configuration.GetConnectionString("Database"));
});
}
public void Configure(
IApplicationBuilder app,
IHostingEnvironment env,
IServiceProvider serviceProvider)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseHsts();
}
app.UseCors("Limited");
app.UseHttpsRedirection();
app.UseMvc();
app.UseSignalR(routes => routes.MapHub<NotifyHub>("/notify"));
}
Angular服务的设置如下:
public class NotifyHub : Hub
{
public override async Task OnConnectedAsync()
{
await base.OnConnectedAsync();
}
public override async Task OnDisconnectedAsync(Exception exception)
{
await base.OnDisconnectedAsync(exception);
}
}
所有NuGet软件包都是最新的(除了Microsoft.NETCore.App为v2.1.0之外,其他所有版本均为v2.1.1)并使用v1.0.2(最新)ASP.NET SignalR NPM package-服务器和客户端侧SignalR相同。
使用一个静态IP地址,我能够使该应用程序连接到本地发布的API(但正在运行IIS 10.0)。
我缺少什么吗?许多技术都是很新的,但是我还不想假设它们有问题。