如何使用 OWIN 自托管的网络 api 服务 index.html
How to serve index.html with web api selfhosted with OWIN
应该是个简单的问题,就是找不到答案
我有一个带有 Web api 的 SPA (AngularJS),它由 Owin 自托管。我使用 Nancy 来提供页面,但我想摆脱 Nancy 并使用 Index.html 作为我的单一页面。
我在这里看到这个问题:How to route EVERYTHING other than Web API to /index.html
我无法使用已接受的答案,因为我没有 MVC 和 HomeController,更新问题中建议的方式也不起作用,我得到 No HTTP resource was found that matches the request URI 'http://admin.localhost:33333/'.
No route providing a controller name was found to match request URI 'http://admin.localhost:33333/'
将 Index.html 移动到项目的根目录。然后 install-package Microsoft.Owin.StaticFiles
在程序包管理器控制台中添加以下代码:
public class Startup
{
public void Configuration(IAppBuilder app)
{
const string rootFolder = ".";
var fileSystem=new PhysicalFileSystem(rootFolder);
var options = new FileServerOptions
{
EnableDefaultFiles = true,
FileSystem = fileSystem
};
app.UseFileServer(options);
}
}
这将默认为您的 Index.html 提供服务。
您可以查看 Scott Allen 的博客以阅读更多内容:
应该是个简单的问题,就是找不到答案
我有一个带有 Web api 的 SPA (AngularJS),它由 Owin 自托管。我使用 Nancy 来提供页面,但我想摆脱 Nancy 并使用 Index.html 作为我的单一页面。
我在这里看到这个问题:How to route EVERYTHING other than Web API to /index.html
我无法使用已接受的答案,因为我没有 MVC 和 HomeController,更新问题中建议的方式也不起作用,我得到 No HTTP resource was found that matches the request URI 'http://admin.localhost:33333/'.
No route providing a controller name was found to match request URI 'http://admin.localhost:33333/'
将 Index.html 移动到项目的根目录。然后 install-package Microsoft.Owin.StaticFiles
在程序包管理器控制台中添加以下代码:
public class Startup
{
public void Configuration(IAppBuilder app)
{
const string rootFolder = ".";
var fileSystem=new PhysicalFileSystem(rootFolder);
var options = new FileServerOptions
{
EnableDefaultFiles = true,
FileSystem = fileSystem
};
app.UseFileServer(options);
}
}
这将默认为您的 Index.html 提供服务。
您可以查看 Scott Allen 的博客以阅读更多内容: