【发布时间】:2018-03-28 22:41:23
【问题描述】:
我正在使用 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(未找到)
我尝试使用网上找到的不同主题配置 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();
Angular 应用程序代码
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');
}
版本信息:
IIS:7.5
APP网包.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 我尝试使用此链接 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/ 启用我的 ApplicationPool 的 LoadUserProfile 属性
但这仍然未能达到 404。
我还尝试在我的应用程序上“附加到进程”以查看是否有任何与我的Hub 或/negotiate url 对应的日志,但没有。
(还添加了404结果的截图)
更新 2
这是从 Web.App 中提取的 package.config
更新 3
这是托管应用程序的服务器的配置。 您可以看到 3 个不同的网站。它们都具有几乎相同的配置。 (只是端口变化,定义了3种不同的测试环境访问)
这是基本的 localhost 开发人员 IIS,我猜我是由 Visual Studio 生成的。
【问题讨论】:
-
您可以发布您的集线器的代码吗?你有身份验证吗?
标签: c# asp.net-core asp.net-core-signalr