我使用ASP.NET Core 2.0与Microsoft.AspNetCore.SignalR(1.0.0-preview1-final) .
我有一个问题是使用IIS(使用Kestrel)部署我的应用程序 . 当我使用IIS Express在localhost中运行服务器时,一切都按预期工作,但当我尝试在IIS(Windows服务器或本地主机Windows 7)上运行时,协商调用失败到404
POST http:// localhost / notification / negotiate 404(Not Found)
我尝试使用在线找到的不同主题配置IIS,但没有成功 . ( <modules runAllManagedModulesForAllRequests="true" />
,带有https://support.microsoft.com/en-gb/help/980368/a-update-is-available-that-enables-certain-iis-7-0-or-iis-7-5-handlers的无扩展名网址)
但我仍然非常确定该问题与我的IIS配置有关,因为整个项目在IIS Express上运行良好...
这是测试服务器上使用的 web.config
文件(我删除了不同的调试尝试,因为它不能正常工作......)
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\MyProject.Web.App.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
<!--ProjectGuid: {{some GUID here}}-->
Configure
方法中使用的部分代码
app.UseSignalR(route =>
{
route.MapHub<NotificationHub>("/notification");
});
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
routes.MapSpaFallbackRoute(
name: "spa-fallback",
defaults: new { controller = "Home", action = "Index" });
});
ConfigureServices
方法中使用的部分代码
services.AddMvc()
services.AddSignalR();
services.AddSession();
角度应用程序代码
constructor() {
/** ... **/
this.hubConnection = new HubConnection('/notification', {
transport: TransportType.LongPolling
});
this.hubConnection.on('Update', (data: string) => {
let res = new DefaultNotificationInfo(data);
/** ... **/
});
this.hubConnection.start()
.then(() => {
this.join().then(next => {
// nothing to do on join, the socket is running
}).catch(error => {
console.error(error)
});
})
.catch(err => {
console.error(err)
});
}
private join(): Promise<any> {
return this.hubConnection.invoke('Join');
}
Versions informations :
IIS: 7.5
APP net package.json:
{
/** ... **/
"@aspnet/signalr": "^1.0.0-preview1-update1",
"@aspnet/signalr-client": "^1.0.0-alpha2-final",
/** ... **/
}
API asp net nuget版本: (1.0.0-preview1-final)
阅读https://blogs.msdn.microsoft.com/webdev/2017/09/14/announcing-signalr-for-asp-net-core-2-0/和https://blogs.msdn.microsoft.com/webdev/2018/02/27/asp-net-core-2-1-0-preview1-getting-started-with-signalr/后,我很确定我已经涵盖了他们的教程/快速启动中的所有内容
我错过了什么吗?
更新1
找到后:https://stackoverflow.com/a/43014264/3198096我尝试使用此链接启用ApplicationPool的LoadUserProfile属性https://blogs.msdn.microsoft.com/vijaysk/2009/03/08/iis-7-tip-3-you-can-now-load-the-user-profile-of-the-application-pool-identity/
但这仍然是404失败 .
我也尝试在我的应用程序上查看"Attach to process"是否有任何与我的 Hub
或 /negotiate
url对应的日志,但没有 .
(还添加了404结果的屏幕截图)
更新2
这是来自Web.App的package.config的摘录
更新3
这是托管应用程序的服务器的配置 . 你可以看到3个不同的网站 . 它们都具有几乎相同的配置 . (只是端口更改,它定义了3种不同的测试环境访问)
这是基本的localhost开发人员IIS,我想我是由Visual Studio生成的 .
2 回答
github上有一个非常类似的问题 . 如果网站没有托管在根目录上(例如,通过使用虚拟目录或类似的东西),SignalR将在编写时使用错误的URL . 例如,如果您的"website-root"已启用
你必须使用
如果以上操作不起作用,我建议您将日志记录添加到客户端应用程序(如上所示)和服务器 . 这将告诉你究竟出了什么问题 .
你的中间件管道中有
app.UseSPA()
吗?如果是这样的话,请尝试在_2369006之后添加它https://github.com/aspnet/SignalR/issues/1511