4

我正在使用自托管的 ServiceStack 开发本地服务器。我硬编码了一个演示网页,并允许在以下位置访问它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}");
}

它适用于 Chrome/Firefox/Opera,但是,IE 会将 url 视为下载请求并宣传“您要从 localhost 打开或保存页面吗?”

我该怎么做才能让IE将url视为网页?(我已经在演示页面中添加了 doctype 标头;但这不能阻止 IE 将其视为下载请求。)

编辑。

好的。访问本地主机时,我使用 Fiddler 检查响应。IE 和 Firefox 得到的响应是完全一样的。在标题中,内容类型写为:

Content-Type: text/html,text/html

Firefox 将此内容类型视为text/html,但 IE 无法识别此内容类型(它只能识别单个text/html)!

所以这让我相信这是由于 SS 中的一个错误。

解决方案

一种解决方案是显式设置内容类型:

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

1 回答 1

1

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.

于 2013-06-18T07:17:25.293 回答