ali
March 30, 2016, 12:38pm
1
If I input english word, It works fine. When I input chinese word, it goes wrong
In the error page, I Clicked the json format, it shows:
{"ResponseStatus":{"ErrorCode":"HttpRequestValidationException","Message":"从客户端(Name=\"好\")中检测到有潜在危险的 Request.QueryString 值。","StackTrace":" 在 System.Web.HttpRequest.ValidateString(String value, String collectionKey, RequestValidationSource requestCollection)\r\n 在 System.Web.HttpRequest.<>c__DisplayClass280_0.<ValidateHttpValueCollection>b__0(String key, String value)\r\n 在 System.Web.HttpValueCollection.EnsureKeyValidated(String key)\r\n 在 System.Web.HttpValueCollection.Get(String name)\r\n 在 ServiceStack.NameValueCollectionWrapper.get_Item(String name)\r\n 在 ServiceStack.HttpRequestExtensions.GetFlattenedRequestParams(IRequest request)\r\n 在 ServiceStack.Host.RestHandler.CreateRequest(IRequest httpReq, IRestPath restPath)\r\n 在 ServiceStack.Host.RestHandler.ProcessRequestAsync(IRequest httpReq, IResponse httpRes, String operationName)"}}
mythz
March 30, 2016, 12:44pm
2
This StackTrace shows that the Exception is occurring inside ASP.NET ’s HttpRequest.ValidateString
, i.e:
System.Web.HttpRequest.ValidateString(String value, String collectionKey, RequestValidationSource requestCollection)\r\n
This validation is built into ASP.NET , you can potentially disable QueryString validation in your Web.config by adding:
<httpRuntime requestValidationMode="2.0" />
ali
March 30, 2016, 1:03pm
3
It Works, thanks! But It will generate
If I use HttpUtility.HtmlDecode(request.Name)
, It shows fine.
Is there any setting or config don’t use ‘HttpUtility.HtmlDecode’ and can get the right result?
mythz
March 30, 2016, 1:23pm
4
No we don’t typically use HtmlDecode when displaying text, but what page is this? Is this a page built into ServiceStack?
ali
March 30, 2016, 2:14pm
5
My project is used ServiceStackVS , choose the project templates “ServiceStack ASP.NET with Razor” , the default project include the hello.cshtml , input the Chinese words It Show Like the Image, you can try input 你好(hello)
https://forums.servicestack.net/uploads/default/_optimized/4d1/e93/38a9bbdcf4_690x161.png
If Click in other formats :json, xml , It Displays Right.
mythz
March 30, 2016, 3:14pm
6
Then you’re just referring to /Views/Hello.cshtml
which is just the default view that’s apart of the template:
@inherits ViewPage<AspNetRazor.ServiceModel.HelloResponse>
<h2 style="color:green">@Model.Result</h2>
<p><a href="/">< home</a></p>
You can customize this as you wish.
ali
March 31, 2016, 1:41am
7
I have found the reason, I added the
‘’ in the _Layout.cshtml , then all works fine.
and removed also works fine.