本文整理汇总了C#中IHttpRequest.GetQueryStringContentType方法的典型用法代码示例。如果您正苦于以下问题:C# IHttpRequest.GetQueryStringContentType方法的具体用法?C# IHttpRequest.GetQueryStringContentType怎么用?C# IHttpRequest.GetQueryStringContentType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IHttpRequest
的用法示例。
在下文中一共展示了IHttpRequest.GetQueryStringContentType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessRequest
public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
{
try
{
EndpointHost.Config.AssertFeatures(format);
if (EndpointHost.ApplyPreRequestFilters(httpReq, httpRes)) return;
httpReq.ResponseContentType = httpReq.GetQueryStringContentType() ?? this.HandlerContentType;
var callback = httpReq.QueryString["callback"];
var doJsonp = EndpointHost.Config.AllowJsonpRequests
&& !string.IsNullOrEmpty(callback);
var request = CreateRequest(httpReq, operationName);
if (EndpointHost.ApplyRequestFilters(httpReq, httpRes, request)) return;
var response = GetResponse(httpReq, httpRes, request);
if (EndpointHost.ApplyResponseFilters(httpReq, httpRes, response)) return;
if (doJsonp && !(response is CompressedResult))
httpRes.WriteToResponse(httpReq, response, (callback + "(").ToUtf8Bytes(), ")".ToUtf8Bytes());
else
httpRes.WriteToResponse(httpReq, response);
}
catch (Exception ex)
{
if (!EndpointHost.Config.WriteErrorsToResponse) throw;
HandleException(httpReq, httpRes, operationName, ex);
}
}
示例2: ProcessRequest
public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
{
try
{
var contentType = httpReq.GetQueryStringContentType() ?? this.HandlerContentType;
var callback = httpReq.QueryString["callback"];
var doJsonp = EndpointHost.Config.AllowJsonpRequests
&& !string.IsNullOrEmpty(callback);
var request = CreateRequest(httpReq, operationName);
var response = GetResponse(httpReq, request);
var serializer = GetStreamSerializer(contentType);
if (doJsonp) httpRes.Write(callback + "(");
httpRes.WriteToResponse(response, serializer, contentType);
if (doJsonp) httpRes.Write(")");
}
catch (Exception ex)
{
var errorMessage = string.Format("Error occured while Processing Request: {0}", ex.Message);
Log.Error(errorMessage, ex);
httpRes.WriteErrorToResponse(HandlerContentType, operationName, errorMessage, ex);
}
}
示例3: ProcessRequest
//public StreamSerializerDelegate GetStreamSerializer(string contentType)
//{
// return GetContentFilters().GetStreamSerializer(contentType);
//}
public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
{
try
{
EndpointHost.Config.AssertFeatures(usesFeature);
httpReq.ResponseContentType = httpReq.GetQueryStringContentType() ?? this.HandlerContentType;
var callback = httpReq.QueryString["callback"];
var doJsonp = EndpointHost.Config.AllowJsonpRequests
&& !string.IsNullOrEmpty(callback);
var request = CreateRequest(httpReq, operationName);
if (EndpointHost.ApplyRequestFilters(httpReq, httpRes, request)) return;
var response = GetResponse(httpReq, request);
if (EndpointHost.ApplyResponseFilters(httpReq, httpRes, response)) return;
if (doJsonp)
httpRes.WriteToResponse(httpReq, response, (callback + "(").ToUtf8Bytes(), ")".ToUtf8Bytes());
else
httpRes.WriteToResponse(httpReq, response);
}
catch (Exception ex)
{
var errorMessage = string.Format("Error occured while Processing Request: {0}", ex.Message);
Log.Error(errorMessage, ex);
httpRes.WriteErrorToResponse(HandlerContentType, operationName, errorMessage, ex);
}
}
示例4: ProcessRequest
//public StreamSerializerDelegate GetStreamSerializer(string contentType)
//{
// return GetContentFilters().GetStreamSerializer(contentType);
//}
public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
{
try
{
EndpointHost.Config.AssertFeatures(usesFeature);
httpReq.ResponseContentType = httpReq.GetQueryStringContentType() ?? this.HandlerContentType;
var callback = httpReq.QueryString["callback"];
var doJsonp = EndpointHost.Config.AllowJsonpRequests
&& !string.IsNullOrEmpty(callback);
var request = CreateRequest(httpReq, operationName);
if (EndpointHost.ApplyRequestFilters(httpReq, httpRes, request)) return;
var response = GetResponse(httpReq, request);
if (EndpointHost.ApplyResponseFilters(httpReq, httpRes, response)) return;
if (doJsonp)
httpRes.WriteToResponse(httpReq, response, (callback + "(").ToUtf8Bytes(), ")".ToUtf8Bytes());
else
httpRes.WriteToResponse(httpReq, response);
}
catch (Exception ex)
{
bool writeErrorToResponse = ServiceStack.Configuration.ConfigUtils.GetAppSetting<bool>(ServiceStack.Configuration.Keys.WriteErrorsToResponse, true);
if(!writeErrorToResponse) {
throw;
}
var errorMessage = string.Format("Error occured while Processing Request: {0}", ex.Message);
Log.Error(errorMessage, ex);
try {
//httpRes.WriteToResponse always calls .Close in it's finally statement so if there is a problem writing to response, by now it will be closed
if(!httpRes.IsClosed) {
httpRes.WriteErrorToResponse(HandlerContentType, operationName, errorMessage, ex);
}
}
catch(Exception WriteErrorEx) {
//Exception in writing to response should not hide the original exception
Log.Info("Failed to write error to response: {0}", WriteErrorEx);
//rethrow the original exception
throw ex;
}
}
}
示例5: ProcessRequestAsync
public override Task ProcessRequestAsync(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
{
try
{
var appHost = HostContext.AppHost;
appHost.AssertFeatures(format);
if (appHost.ApplyPreRequestFilters(httpReq, httpRes))
return EmptyTask;
httpReq.ResponseContentType = httpReq.GetQueryStringContentType() ?? this.HandlerContentType;
var callback = httpReq.QueryString["callback"];
var doJsonp = HostContext.Config.AllowJsonpRequests
&& !string.IsNullOrEmpty(callback);
var request = CreateRequest(httpReq, operationName);
if (appHost.ApplyRequestFilters(httpReq, httpRes, request))
return EmptyTask;
var rawResponse = GetResponse(httpReq, httpRes, request);
return HandleResponse(rawResponse, response =>
{
if (appHost.ApplyResponseFilters(httpReq, httpRes, response))
return EmptyTask;
if (doJsonp && !(response is CompressedResult))
return httpRes.WriteToResponse(httpReq, response, (callback + "(").ToUtf8Bytes(),")".ToUtf8Bytes());
return httpRes.WriteToResponse(httpReq, response);
},
ex => !HostContext.Config.WriteErrorsToResponse
? ex.AsTaskException()
: HandleException(httpReq, httpRes, operationName, ex));
}
catch (Exception ex)
{
return !HostContext.Config.WriteErrorsToResponse
? ex.AsTaskException()
: HandleException(httpReq, httpRes, operationName, ex);
}
}