加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-web-api – 如何使用OWIN自动主机的web api来提供index.

发布时间:2020-12-16 00:46:27 所属栏目:asp.Net 来源:网络整理
导读:应该是一个容易的问题,只是找不到答案。 我有一个SPA(AngularJS)与web api是自主托管与Owin。我使用Nancy来提供这个页面,但是我想摆脱Nancy并将Index.html用作我的单页。 我在这里看到这个问题:How to route EVERYTHING other than Web API to /index.htm
应该是一个容易的问题,只是找不到答案。

我有一个SPA(AngularJS)与web api是自主托管与Owin。我使用Nancy来提供这个页面,但是我想摆脱Nancy并将Index.html用作我的单页。

我在这里看到这个问题:How to route EVERYTHING other than Web API to /index.html

我不能使用可接受的答案,因为我没有MVC和HomeController,在更新的问题中建议的方式不起作用,我得到没有发现HTTP资源匹配请求URI’http://admin.localhost :33333 /”。没有发现提供控制器名称的路由匹配请求URI’http://admin.localhost:33333 /’

解决方法

将您的Index.html移动到项目的根目录。然后在Package Manager Console中安装包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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读