HTML page with images using .net WebApi

后端 未结 2 890
伪装坚强ぢ
伪装坚强ぢ 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:07

    WebApi can serve static file.

    So you just have to set the right link in your html file.

    For example:

    Your <img> will be like this:

    <img src="~/Content/img/email-icon.png" />

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题