Yin Zhu
Yin Zhu

Reputation: 17119

IE treats a url as a download not as an HTML page

I am developing a local server using self-hosted ServiceStack. I hardcoded a demo webpage and allow it to be accessed at 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 fine for Chrome/Firefox/Opera, however, IE would treat the url as a download request and promote "Do you want to open or save page from localhost?"

What shall I do to let IE treat the url as a web page? (I already added doctype headers to the demo page; but that cannot prevent IE from treating it as a download request.)

EDIT.

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

Content-Type: text/html,text/html

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

So this leads me to believe that this is due to a bug in SS.

Solution

One solution is to explicitly set the content type:

        return new HttpResult(
            new MemoryStream(Encoding.UTF8.GetBytes(html)), "text/html");

Upvotes: 4

Views: 231

Answers (1)

kunjee
kunjee

Reputation: 2759

I don't know what is your exact problem is. If you want to serve html page, there is a different way to do that.

Servicestack support razor engine as plugin that is useful if you like to serve html page and also you can bind data with it. Different way of doing this is explain here. razor.servicestack.net . This may be useful. Let me know if you need any additional details.

Upvotes: 1

Related Questions