应该是一个简单的问题,只是找不到答案。
我有一个带有 Web api 的 SPA (AngularJS),它由 Owin 自托管。我使用 Nancy 来提供页面服务,但我想摆脱 Nancy 并使用 Index.html 作为我的单页面。
我在这里看到过这个问题:如何将除 Web API 之外的所有内容路由到 /index.html https://stackoverflow.com/questions/19643001/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 的博客以了解更多内容:
http://odetocode.com/blogs/scott/archive/2014/02/10/building-a-simple-file-server-with-owin-and-katana.aspx http://odetocode.com/blogs/scott/archive/2014/02/10/building-a-simple-file-server-with-owin-and-katana.aspx
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)