IE treats URLs as downloads not as HTML pages

I am developing a local server using a self-service ServiceStack. I hard-coded the demo web page and allowed its access to localhost:8080/page :

 public class PageService : IService<Page> { public object Execute(Page request) { var html = System.IO.File.ReadAllText(@"demo_chat2.html"); return html; } } // set route public override void Configure(Container container) { Routes .Add<Page>("/page") .Add<Hello>("/hello") .Add<Hello>("/hello/{Name}"); } 

It works great for Chrome / Firefox / Opera, however IE will handle the URL as a download request and promote "Do you want to open or save the page from a local host?"

What should I do to make IE treat the URL as a web page? (I already added the doctype headers to the demo page, but that can't stop IE from seeing this as a download request.)

EDIT.

Ok I used Fiddler to check the response when accessing localhost. The responses that IE and Firefox receive are exactly the same. And in the header, the content type is written as:

 Content-Type: text/html,text/html 

Firefox treats this type of content as text/html , however IE does not recognize this type of content (it only recognizes one text/html )!

So, it makes me believe that this is due to an error in SS.

Decision

One solution is to explicitly set the content type:

  return new HttpResult( new MemoryStream(Encoding.UTF8.GetBytes(html)), "text/html"); 
+4
source share
1 answer

I do not know what your exact problem is. If you want to serve the html page, there is another way to do this.

Servicestack supports the shaving engine as a plugin, which is useful if you want to serve an html page, and you can also associate data with it. This explains another way to do this. razor.servicestack.net . This may be helpful. Let me know if you need more details.

+1
source

Source: https://habr.com/ru/post/1486599/


All Articles