C# 在本地IIS上发布的带有signalr的blazor服务器项目一旦停止正常工作,并在连续加载中返回空页 在本教程(链接)之后,我使用blazor服务器和SignalR开发了一个应用程序。 该应用程序由visual studio完美执行。 然后,我在本地IIS上发布了该应用程序,以便使用不同的设备而不是一台设备进行更真实的测试。 该应用程序显然是毫无问题地发布的。 我把它放在端口80上,以便在默认情况下仅通过连接到本地主机进行连接。 第一次运行时,应用程序工作正常,我能够毫无问题地使用这些功能。 之后,当我尝试连接到应用程序时,页面不再加载并保持白色。
我了解到问题可能与默认禁用的IIS web套接字有关。 我已经尝试在一些stackoverflow响应后激活它们,但没有任何更改。 首次运行结果: 首次运行结果:C# 在本地IIS上发布的带有signalr的blazor服务器项目一旦停止正常工作,并在连续加载中返回空页 在本教程(链接)之后,我使用blazor服务器和SignalR开发了一个应用程序。 该应用程序由visual studio完美执行。 然后,我在本地IIS上发布了该应用程序,以便使用不同的设备而不是一台设备进行更真实的测试。 该应用程序显然是毫无问题地发布的。 我把它放在端口80上,以便在默认情况下仅通过连接到本地主机进行连接。 第一次运行时,应用程序工作正常,我能够毫无问题地使用这些功能。 之后,当我尝试连接到应用程序时,页面不再加载并保持白色。,c#,asp.net-core,signalr,blazor,iis-8,C#,Asp.net Core,Signalr,Blazor,Iis 8,我了解到问题可能与默认禁用的IIS web套接字有关。 我已经尝试在一些stackoverflow响应后激活它们,但没有任何更改。 首次运行结果: 首次运行结果: 本人附上申请代码: 枢纽: 视图: @page/“ @使用Microsoft.AspNetCore.signal.Client @注入导航管理器_导航管理器 聊天应用 用户: 信息: 发送 @path.ToString() @绝对路径URI @foreach(var消息在_消息中) { @信息 } @错误 @代码{ 专用
本人附上申请代码: 枢纽: 视图:
@page/“
@使用Microsoft.AspNetCore.signal.Client
@注入导航管理器_导航管理器
聊天应用
用户:
信息:
发送
@path.ToString()
@绝对路径URI
@foreach(var消息在_消息中)
{
-
@信息
}
@错误
@代码{
专用HUB连接_HUB连接;
私有字符串_userInput=“”;
私有字符串_message=“”;
私有Uri路径;
私有列表_messages=新列表();
私有字符串错误=”;
受保护的重写异步任务OnInitializedAsync()
{
尝试
{
路径=_navManager.toabsolutioneuri(“/chatHub”);
_hubConnection=新的HubConnectionBuilder()。
WithUrl(路径)
.Build();
_hubConnection.On(“ReceiveMessage”(用户,消息)=>
{
var encodeMS=$“{user}:{message}”;
_messages.Add(encodeMS);
StateHasChanged();
});
wait_hubConnection.StartAsync();
}
捕获(例外e)
{
错误=e.消息;
}
}
任务发送()=>
_hubConnection.SendAsync(“SendMessage”,\u userInput,\u message);
公共广播已断开=>
_hubConnection.State==HubConnectionState.Connected;
}
启动:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using BlazorApp2.Data;
namespace BlazorApp2
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPages();
services.AddServerSideBlazor();
services.AddSingleton<WeatherForecastService>();
services.AddSignalR();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
endpoints.MapHub<ChatHub>("/chatHub");
});
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Threading.Tasks;
使用Microsoft.AspNetCore.Builder;
使用Microsoft.AspNetCore.Components;
使用Microsoft.AspNetCore.Hosting;
使用Microsoft.AspNetCore.HttpsPolicy;
使用Microsoft.Extensions.Configuration;
使用Microsoft.Extensions.DependencyInjection;
使用Microsoft.Extensions.Hosting;
使用BlazorApp2.Data;
名称空间BlazorApp2
{
公营创业
{
公共启动(IConfiguration配置)
{
配置=配置;
}
公共IConfiguration配置{get;}
//此方法由运行时调用。请使用此方法将服务添加到容器中。
//有关如何配置应用程序的更多信息,请访问https://go.microsoft.com/fwlink/?LinkID=398940
public void配置服务(IServiceCollection服务)
{
services.AddRazorPages();
AddServerSideBlazor();
services.AddSingleton();
services.AddSignalR();
}
//此方法由运行时调用。请使用此方法配置HTTP请求管道。
public void配置(IApplicationBuilder应用程序、IWebHostEnvironment环境)
{
if(env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
其他的
{
app.UseExceptionHandler(“/Error”);
//默认的HSTS值为30天。您可能希望在生产场景中更改此值,请参阅https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseEndpoints(端点=>
{
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage(“/_主机”);
endpoints.MapHub(“/chatHub”);
});
}
}
}
浏览器控制台中没有错误消息等?没有,0错误:(只是为了确认-您确实通过角色/功能选项在服务器上安装了WebSockets功能-然后重新启动了服务器?(我让Blazor服务器端在IIS上运行完全正常)是的,我添加了这些功能,然后重新启动了服务器。我注意到,即使在项目的属性中,我将参数“start”从IIS Express更改为degugI中的IIS,也会出现问题。我遇到了相同的问题,您解决了吗?浏览器控制台中没有错误消息等?不,0错误:(只是确认一下-您已经通过角色/功能选项在服务器上安装了WebSockets功能-然后重新启动了服务器?(我让Blazor ServerSide在IIS上运行完全正常)是的,我添加了这些功能,然后重新启动了服务器。我注意到,即使在项目的属性中,我将参数“start”从IIS Express更改为degugI中的IIS,也会出现问题。我遇到了相同的问题,您解决了吗?
@page "/"
@using Microsoft.AspNetCore.SignalR.Client
@inject NavigationManager _navManager
<div class="row">
<div class="col-md-4">
<h2>
Chat app
</h2>
<div class="form-group">
<label>
User : <input type="text" class="form-control" @bind="_userInput" />
</label>
</div>
<div class="form-group">
<label>
Message : <input type="text" class="form-control" @bind="_message" />
</label>
</div>
<button @onclick="Send" disabled="@(!IsConnected)">Send</button>
</div>
</div>
<p>@path.ToString()</p>
<p>@path.AbsoluteUri</p>
<hr />
<ul id="messageList">
@foreach(var message in _messages)
{
<li>
@message
</li>
}
</ul>
@error
@code{
private HubConnection _hubConnection;
private string _userInput = "";
private string _message = "";
private Uri path;
private List<string> _messages = new List<string>();
private string error = "";
protected override async Task OnInitializedAsync()
{
try
{
path = _navManager.ToAbsoluteUri("/chatHub");
_hubConnection = new HubConnectionBuilder().
WithUrl(path)
.Build();
_hubConnection.On<string, string>("ReciveMessage", (user, message) =>
{
var encodeMS = $"{user}:{message}";
_messages.Add(encodeMS);
StateHasChanged();
});
await _hubConnection.StartAsync();
}
catch (Exception e)
{
error = e.Message;
}
}
Task Send() =>
_hubConnection.SendAsync("SendMessage", _userInput, _message);
public bool IsConnected =>
_hubConnection.State == HubConnectionState.Connected;
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using BlazorApp2.Data;
namespace BlazorApp2
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPages();
services.AddServerSideBlazor();
services.AddSingleton<WeatherForecastService>();
services.AddSignalR();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
endpoints.MapHub<ChatHub>("/chatHub");
});
}
}
}