HTML page with images using .net WebApi

后端 未结 2 893
伪装坚强ぢ
伪装坚强ぢ 2021-01-25 17:08

I\'m using .net WebApi to expose different endpoints with JSON data. Now I need that an specific endpoint returns HTMLs pages. I have implemented it like this.

[         


        
2条回答
  •  别那么骄傲
    2021-01-25 18:10

    Finally I solved it. I added a static file server middleware using owin+katana.

    I changed my startup class using this

    public void Configuration(IAppBuilder application)
        {
            //Other webApi configuration
                application.UseFileServer(new FileServerOptions()
                {
                    RequestPath = new PathString("/html/public"),
                    FileSystem = new PhysicalFileSystem(@"../../../MyProject/html/public"),
                });
    

    Now automatically all images scripts and files that are under public are served when my html page is requested via my webApi.

    What does this code is to translate my http requests "/html/public" to my real file system path specified in PhysicalFileSystem.

    Hope this help anybody.

提交回复
热议问题