要访问IOwinContex
,我们需要致电Context.Request.GetHttpContext().GetOwinContext();
但Context.Request.GetHttpContext()
会返回null
;
我查了Context.Request.Environment
字典。它不包含HttpContextBase
实例。为什么会这样?
在Windows 7应用程序上配置自托管OWIN:
using Microsoft.AspNet.SignalR;
using Microsoft.Owin;
using Microsoft.Owin.FileSystems;
using Microsoft.Owin.Hosting;
using Microsoft.Owin.StaticFiles;
using Owin;
//...
private void StartSerice()
{
WebApp.Start("http://127.0.0.1:8080/", (app) =>
{
app.Map("/api", map =>
{
map.RunSignalR(new HubConfiguration
{
EnableDetailedErrors = true
});
});
app.UseFileServer(new FileServerOptions
{
EnableDefaultFiles = true,
FileSystem = new PhysicalFileSystem("./www"),
EnableDirectoryBrowsing = false,
RequestPath = new PathString("")
});
}
}
AccountHub
上课:
public class AccountHub : Hub
{
public void TestMethod(string message)
{
HttpContextBase httpContextBase = Context.Request.GetHttpContext(); // is null
//...
}
}