我有一个servicestack服务器,它使用响应过滤器向我们的服务添加数据验证消息。我的Put / Post处理程序返回一个HttpResult对象,其Response设置为我们的验证对象。然后,响应过滤器将此对象分解为将其设置为Response对象的原始html字符串。为了使其工作,我必须在“views”中创建一个String.md文件以及一个空白的html模板文件。我现在看到的问题是当我们的自定义html响应包含逗号“,”jsv fromater尝试序列化字符串并抛出异常:
at System.String.get_Chars(Int32 index)
at ServiceStack.Text.Jsv.JsvTypeSerializer.EatMapKey(String value, Int32& i)
at ServiceStack.Text.Common.DeserializeDictionary`1.ParseStringDictionary(String value)
at ServiceStack.Text.Jsv.JsvReader`1.Parse(String value)
at ServiceStack.Text.TypeSerializer.DeserializeFromString[T](String value)
at ServiceStack.Html.ViewDataDictionary.PopulateModelState()
at ServiceStack.Html.HtmlHelper.Init(IViewEngine viewEngine, ViewDataDictionary viewData)
at ServiceStack.Html.HtmlHelper.Init(MarkdownPage markdownPage, Dictionary`2 scopeArgs, Boolean renderHtml, ViewDataDictionary viewData)
at ServiceStack.Markdown.MarkdownViewBase.Init(IAppHost appHost, MarkdownPage markdownPage, Dictionary`2 scopeArgs, Object model, Boolean renderHtml)
at ServiceStack.WebHost.Endpoints.Support.Markdown.MarkdownPage.Write(TextWriter textWriter, PageContext pageContext)
at ServiceStack.WebHost.Endpoints.Support.Markdown.TemplateExtensions.RenderToString(MarkdownPage markdownPage, Dictionary`2 scopeArgs, Boolean renderHtml)
at ServiceStack.WebHost.Endpoints.Formats.MarkdownFormat.RenderDynamicPage(MarkdownPage markdownPage, Dictionary`2 scopeArgs, Boolean renderHtml, Boolean renderTemplate)
at ServiceStack.WebHost.Endpoints.Formats.MarkdownFormat.RenderDynamicPage(MarkdownPage markdownPage, String pageName, Object model, Boolean renderHtml, Boolean renderTemplate)
at ServiceStack.WebHost.Endpoints.Formats.MarkdownFormat.ProcessMarkdownPage(IHttpRequest httpReq, MarkdownPage markdownPage, Object dto, IHttpResponse httpRes)
at ServiceStack.WebHost.Endpoints.Formats.MarkdownFormat.<Register>b__1(IRequestContext requestContext, Object dto, IHttpResponse httpRes)
at ServiceStack.WebHost.Endpoints.Formats.HtmlFormat.<>c__DisplayClass1.<SerializeToStream>b__0(StreamSerializerResolverDelegate x)
at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
at ServiceStack.WebHost.Endpoints.Formats.HtmlFormat.SerializeToStream(IRequestContext requestContext, Object dto, IHttpResponse httpRes)
at ServiceStack.Common.Web.HttpResponseFilter.SerializeToStream(IRequestContext requestContext, Object response, Stream responseStream) in i:\GitHub\ServiceStack\src\ServiceStack.Common\Web\HttpResponseFilter.cs:line 152
at ServiceStack.Common.Web.HttpResult.WriteTo(Stream responseStream) in i:\GitHub\ServiceStack\src\ServiceStack.Common\Web\HttpResult.cs:line 219
at ServiceStack.WebHost.Endpoints.Extensions.HttpResponseExtensions.WriteToOutputStream(IHttpResponse response, Object result, Byte[] bodyPrefix, Byte[] bodySuffix)
at ServiceStack.WebHost.Endpoints.Extensions.HttpResponseExtensions.WriteToResponse(IHttpResponse response, Object result, ResponseSerializerDelegate defaultAction, IRequestContext serializerCtx, Byte[] bodyPrefix, Byte[] bodySuffix)
我的问题是如何才能将这些回复变为jsv?或者有更好的方法来返回原始HTML?我不能让我的请求处理程序返回一个字符串,因为我需要控制响应代码和返回的标题。
答案 0 :(得分:0)
您可以在HttpResult中返回HTML字符串,例如:
return new HttpResult("<html>...</html>", ContentType.Html);
对于引用,可以在以下位置找到ServiceStack的HTML Story:
Is it possible to serve HTML pages with ServiceStack?
除了Markdown之外,我们还添加了新的MVC Razor支持,您可以看到以下示例: