本文整理汇总了C#中IHttpResponse.Write方法的典型用法代码示例。如果您正苦于以下问题:C# IHttpResponse.Write方法的具体用法?C# IHttpResponse.Write怎么用?C# IHttpResponse.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IHttpResponse
的用法示例。
在下文中一共展示了IHttpResponse.Write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public void Execute(IHttpRequest httpReq, IHttpResponse httpRes)
{
EndpointHost.Config.AssertFeatures(Feature.Metadata);
httpRes.ContentType = "text/xml";
var baseUri = httpReq.GetParentBaseUrl();
var optimizeForFlash = httpReq.QueryString["flash"] != null;
var includeAllTypesInAssembly = httpReq.QueryString["includeAllTypes"] != null;
var operations = new XsdMetadata(
EndpointHost.Metadata, flash: optimizeForFlash, includeAllTypes: includeAllTypesInAssembly);
try
{
var wsdlTemplate = GetWsdlTemplate(operations, baseUri, optimizeForFlash, includeAllTypesInAssembly, httpReq.GetBaseUrl());
httpRes.Write(wsdlTemplate.ToString());
}
catch (Exception ex)
{
log.Error("Autogeneration of WSDL failed.", ex);
httpRes.Write("Autogenerated WSDLs are not supported "
+ (Env.IsMono ? "on Mono" : "with this configuration"));
}
}
示例2: Execute
public override void Execute(IHttpRequest req, IHttpResponse res, object requestDto)
{
var applicationRequest = requestDto as ApplicationRequest;
var appKey = GetAppKeyFromRequest(req, applicationRequest);
var appSecret = GetAppSecretFromRequest(req, applicationRequest);
var app = ApplicationAuthenticationService.Authenticate(appKey,appSecret);
if (app == null)
{
res.StatusCode = (int)HttpStatusCode.Forbidden;
// Some Android devices require a body, otherwise the response code is ignored and set 0
res.Write(HttpStatusCode.Forbidden.ToString());
res.Close();
}
if (applicationRequest != null)
{
applicationRequest.AppKey = appKey;
applicationRequest.AppSecret = appSecret;
applicationRequest.Application = ApplicationRepository.FindApplication(appKey, appSecret);
applicationRequest.Account = AccountApplicationRepository.GetForApplication(applicationRequest.Application.Id);
}
var validationErrors = ValidateRequest(applicationRequest);
if (validationErrors.Any())
{
res.StatusCode = (int)HttpStatusCode.BadRequest;
// Some Android devices require a body, otherwise the response code is ignored and set 0
res.Write(HttpStatusCode.BadRequest.ToString());
foreach (var error in validationErrors)
{
res.Write(error);
}
res.Close();
}
}
示例3: ProcessRequest
public void ProcessRequest(IHttpRequest request, IHttpResponse response, string operationName)
{
response.ContentType = "text/plain";
response.StatusCode = 404;
response.Write("Handler for Request not found: \n\n");
response.Write("\nRequest.HttpMethod: " + request.HttpMethod);
response.Write("\nRequest.PathInfo: " + request.PathInfo);
response.Write("\nRequest.QueryString: " + request.QueryString);
response.Write("\nRequest.RawUrl: " + request.RawUrl);
}
示例4: Replay
public Task Replay(IHttpResponse response)
{
return response.Write(stream =>
{
lock (_locker)
{
_stream.Position = 0;
return _stream.CopyToAsync(stream);
}
});
}
示例5: Replay
public void Replay(IHttpResponse response)
{
response.Write(stream =>
{
lock (_locker)
{
_stream.Position = 0;
_stream.CopyTo(stream);
}
});
}
示例6: Write
// Only hitting this with integration tests
public void Write(IHttpResponse response)
{
response.WriteContentType(ContentType.Value);
response.WriteResponseCode(HttpStatusCode.OK);
/* TODO -- add later, but not NOW
response.AppendHeader(HttpResponseHeaders.CacheControl, _cacheHeader);
var expiresKey = DateTime.UtcNow.AddSeconds(AssetSettings.MaxAgeInSeconds).ToString("R");
response.AppendHeader(HttpResponseHeaders.Expires, expiresKey);
*/
response.Write(stream => stream.Write(Contents(), 0, Contents().Length));
}
示例7: Execute
public void Execute(IHttpRequest httpReq, IHttpResponse httpRes)
{
httpRes.ContentType = "text/xml";
var baseUri = httpReq.AbsoluteUri; // .GetParentBaseUrl();
var optimizeForFlash = httpReq.QueryString["flash"] != null;
var includeAllTypesInAssembly = httpReq.QueryString["includeAllTypes"] != null;
var operations = includeAllTypesInAssembly ? EndpointHost.AllServiceOperations : EndpointHost.ServiceOperations;
var wsdlTemplate = GetWsdlTemplate(operations, baseUri, optimizeForFlash, includeAllTypesInAssembly, httpReq.GetPathUrl());
httpRes.Write(wsdlTemplate.ToString());
}
示例8: Execute
public void Execute(IHttpRequest httpReq, IHttpResponse httpRes)
{
HostContext.AppHost.AssertFeatures(Feature.Metadata);
httpRes.ContentType = "text/xml";
var baseUri = httpReq.GetParentBaseUrl();
var optimizeForFlash = httpReq.QueryString["flash"] != null;
var operations = new XsdMetadata(HostContext.Metadata, flash: optimizeForFlash);
try
{
var wsdlTemplate = GetWsdlTemplate(operations, baseUri, optimizeForFlash, httpReq.ResolveBaseUrl(), HostContext.Config.SoapServiceName);
httpRes.Write(wsdlTemplate.ToString());
}
catch (Exception ex)
{
log.Error("Autogeneration of WSDL failed.", ex);
httpRes.Write("Autogenerated WSDLs are not supported "
+ (Env.IsMono ? "on Mono" : "with this configuration"));
}
}
示例9: ProcessRequest
public void ProcessRequest(IHttpRequest request, IHttpResponse response, string operationName)
{
var text = new StringBuilder("Handler for Request not found: \n\n")
.AppendLine("Request.HttpMethod: " + request.HttpMethod)
.AppendLine("Request.HttpMethod: " + request.HttpMethod)
.AppendLine("Request.PathInfo: " + request.PathInfo)
.AppendLine("Request.QueryString: " + request.QueryString)
.AppendLine("Request.RawUrl: " + request.RawUrl).ToString();
response.ContentType = "text/plain";
response.StatusCode = 404;
response.Write(text);
response.Close();
}
示例10: HandleException
private static void HandleException(IHttpRequest request, IHttpResponse response,
string operation_name, Exception e,
object request_dto = null)
{
// log the exception
ILog logger = LogManager.GetLogger (typeof(ExceptionHandler));
// create appropriate response
// don't even think about turning this into a switch statement - won't work!
if (e is UnauthorizedException) {
var ex = (UnauthorizedException) e;
//logger.Debug (ex.ErrorMessage);
//LogExceptionDetails (logger, e);
if (ex.UserStatus.StartsWith ("Moderation")) {
response.StatusCode = 412;
response.StatusDescription = ex.UserStatus;
response.ContentType = request.ContentType;
} else {
response.StatusCode = 401;
response.StatusDescription = "Unauthorized.";
response.ContentType = request.ContentType;
}
// TODO provide JSON error objects
} else if (e is ValidationException) {
var ex = (ValidationException) e;
logger.Debug (ex.ErrorMessage);
LogExceptionDetails (logger, e);
response.StatusCode = 400;
response.StatusDescription = "Bad request. Detail:" + e.Message;
} else if (e is RainyBaseException) {
var ex = (RainyBaseException) e;
logger.Debug (ex.ErrorMessage);
LogExceptionDetails (logger, e);
response.StatusCode = 400;
response.StatusDescription = ex.ErrorMessage;
} else {
logger.Debug (e.Message);
LogExceptionDetails (logger, e);
response.StatusCode = 500;
response.StatusDescription = "Internal server error: " + e.Message;
}
// display nice message if viewed in browser
if (request.AcceptTypes.Contains ("text/html")) {
response.Write ("<h1>" + response.StatusCode + "</h1>" +
"<p>" + response.StatusDescription + "</p>");
}
response.EndServiceStackRequest ();
throw e;
}
示例11: ProcessRequest
public void ProcessRequest(IHttpRequest request, IHttpResponse response, string operationName)
{
Log.ErrorFormat("{0} Request not found: {1}", request.UserHostAddress, request.RawUrl);
var text = new StringBuilder("Handler for Request not found: \n\n")
.AppendLine("Request.HttpMethod: " + request.HttpMethod)
.AppendLine("Request.HttpMethod: " + request.HttpMethod)
.AppendLine("Request.PathInfo: " + request.PathInfo)
.AppendLine("Request.QueryString: " + request.QueryString)
.AppendLine("Request.RawUrl: " + request.RawUrl).ToString();
response.ContentType = "text/plain";
response.StatusCode = 404;
response.Write(text);
ServiceStack.WebHost.Endpoints.EndpointHost.AddGlobalResponseHeaders(response);
response.Close();
}
示例12: ProcessRequest
public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
{
var responseContentType = EndpointHost.Config.DefaultContentType;
try
{
var restPath = GetRestPath(httpReq.HttpMethod, httpReq.PathInfo);
if (restPath == null)
throw new NotSupportedException("No RestPath found for: " + httpReq.HttpMethod + " " + httpReq.PathInfo);
operationName = restPath.RequestType.Name;
var callback = httpReq.QueryString["callback"];
var doJsonp = EndpointHost.Config.AllowJsonpRequests
&& !string.IsNullOrEmpty(callback);
responseContentType = httpReq.GetResponseContentType();
var request = GetRequest(httpReq, restPath);
var response = GetResponse(httpReq, request);
if (responseContentType.Contains("jsv") && !string.IsNullOrEmpty(httpReq.QueryString["debug"]))
{
JsvSyncReplyHandler.WriteDebugResponse(httpRes, response);
return;
}
var serializer = GetContentFilters().GetStreamSerializer(responseContentType);
if (doJsonp) httpRes.Write(callback + "(");
httpRes.WriteToResponse(response, serializer, responseContentType);
if (doJsonp) httpRes.Write(")");
}
catch (Exception ex)
{
var errorMessage = string.Format("Error occured while Processing Request: {0}", ex.Message);
Log.Error(errorMessage, ex);
var attrEndpointType = ContentType.GetEndpointAttributes(responseContentType);
httpRes.WriteErrorToResponse(attrEndpointType, operationName, errorMessage, ex);
}
}
示例13: ProcessRequest
public void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
{
var response = this.RequestInfo ?? GetRequestInfo(httpReq);
response.HandlerFactoryArgs = HttpHandlerFactory.DebugLastHandlerArgs;
response.DebugString = "";
if (HttpContext.Current != null)
{
response.DebugString += HttpContext.Current.Request.GetType().FullName
+ "|" + HttpContext.Current.Response.GetType().FullName;
}
var json = JsonSerializer.SerializeToString(response);
httpRes.ContentType = MimeTypes.Json;
httpRes.Write(json);
}
示例14: Replay
public Task Replay(IHttpResponse response)
{
return response.Write(_text);
}
示例15: WriteHeader
public void WriteHeader(IHttpResponse response)
{
// TODO: Eventually I'd like to make this write as it goes instead of
// buffering into a stream, but I need to create the ResponseStream
// type first.
response.Write(ToHeaderString());
}