本文整理汇总了C#中IHttpResponse类的典型用法代码示例。如果您正苦于以下问题:C# IHttpResponse类的具体用法?C# IHttpResponse怎么用?C# IHttpResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IHttpResponse类属于命名空间,在下文中一共展示了IHttpResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AssertAccess
protected bool AssertAccess(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
{
if (!EndpointHost.Config.HasFeature(Feature.Metadata))
{
EndpointHost.Config.HandleErrorResponse(httpReq, httpRes, HttpStatusCode.Forbidden, "Metadata Not Available");
return false;
}
if (EndpointHost.Config.MetadataVisibility != EndpointAttributes.Any)
{
var actualAttributes = httpReq.GetAttributes();
if ((actualAttributes & EndpointHost.Config.MetadataVisibility) != EndpointHost.Config.MetadataVisibility)
{
EndpointHost.Config.HandleErrorResponse(httpReq, httpRes, HttpStatusCode.Forbidden, "Metadata Not Visible");
return false;
}
}
if (operationName == null) return true; //For non-operation pages we don't need to check further permissions
if (!EndpointHost.Config.EnableAccessRestrictions) return true;
if (!EndpointHost.Config.MetadataPagesConfig.IsVisible(httpReq, Format, operationName))
{
EndpointHost.Config.HandleErrorResponse(httpReq, httpRes, HttpStatusCode.Forbidden, "Service Not Available");
return false;
}
return true;
}
示例2: ProcessRequest
public new void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
{
EndpointHost.Config.AssertFeatures(Feature.Metadata);
var operations = EndpointHost.ServiceOperations;
if (httpReq.QueryString["xsd"] != null)
{
var xsdNo = Convert.ToInt32(httpReq.QueryString["xsd"]);
var schemaSet = XsdUtils.GetXmlSchemaSet(operations.AllOperations.Types);
var schemas = schemaSet.Schemas();
var i = 0;
if (xsdNo >= schemas.Count)
{
throw new ArgumentOutOfRangeException("xsd");
}
httpRes.ContentType = "text/xml";
foreach (XmlSchema schema in schemaSet.Schemas())
{
if (xsdNo != i++) continue;
schema.Write(httpRes.Output);
break;
}
return;
}
var writer = new HtmlTextWriter(httpRes.Output);
httpRes.ContentType = "text/html";
ProcessOperations(writer, httpReq);
writer.Flush();
}
示例3: GetResponse
public override object GetResponse(IHttpRequest httpReq, IHttpResponse httpRes, object request)
{
var requestContentType = ContentType.GetEndpointAttributes(httpReq.ResponseContentType);
return ExecuteService(request,
HandlerAttributes | requestContentType | GetEndpointAttributes(httpReq), httpReq, httpRes);
}
示例4: ProcessRequest
public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
{
var isDebugRequest = httpReq.RawUrl.ToLower().Contains("debug");
if (!isDebugRequest)
{
base.ProcessRequest(httpReq, httpRes, operationName);
return;
}
try
{
var request = CreateRequest(httpReq, operationName);
var response = ExecuteService(request,
HandlerAttributes | GetEndpointAttributes(httpReq), httpReq);
WriteDebugResponse(httpRes, response);
}
catch (Exception ex)
{
var errorMessage = string.Format("Error occured while Processing Request: {0}", ex.Message);
httpRes.WriteErrorToResponse(EndpointAttributes.Jsv, operationName, errorMessage, ex);
}
}
示例5: AuthenticateBasicAuth
//Also shared by RequiredRoleAttribute and RequiredPermissionAttribute
public static User AuthenticateBasicAuth(IHttpRequest req, IHttpResponse res)
{
var userCredentialsPair = req.GetBasicAuthUserAndPassword();
var email = userCredentialsPair.HasValue ? userCredentialsPair.Value.Key : String.Empty;
var password = userCredentialsPair.HasValue ? userCredentialsPair.Value.Value : String.Empty;
User user = null;
bool isValid = false;
using (var session = NHibernateHelper.OpenSession())
{
using (var transaction = session.BeginTransaction())
{
var userQuery = session.QueryOver<User>()
.Where(table => table.Email == email)
.And(table => table.Password == password);
user = userQuery.SingleOrDefault();
transaction.Commit();
isValid = (user != null);
}
}
if (!isValid)
{
res.StatusCode = (int)HttpStatusCode.Unauthorized;
res.EndServiceStackRequest();
}
return user;
}
示例6: ProcessRequest
public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
{
httpRes.ContentType = ContentType.Html;
if (RazorFormat == null)
RazorFormat = RazorFormat.Instance;
var contentPage = RazorPage ?? RazorFormat.FindByPathInfo(PathInfo);
if (contentPage == null)
{
httpRes.StatusCode = (int)HttpStatusCode.NotFound;
httpRes.EndHttpRequest();
return;
}
if (RazorFormat.WatchForModifiedPages)
RazorFormat.ReloadIfNeeeded(contentPage);
//Add good caching support
//if (httpReq.DidReturn304NotModified(contentPage.GetLastModified(), httpRes))
// return;
var model = Model;
if (model == null)
httpReq.Items.TryGetValue("Model", out model);
if (model == null)
{
var modelType = RazorPage != null ? RazorPage.GetRazorTemplate().ModelType : null;
model = modelType == null || modelType == typeof(DynamicRequestObject)
? null
: DeserializeHttpRequest(modelType, httpReq, httpReq.ContentType);
}
RazorFormat.ProcessRazorPage(httpReq, contentPage, model, httpRes);
}
示例7: 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);
}
}
示例8: 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);
}
}
示例9: Process
public override bool Process(IHttpRequest request, IHttpResponse response, IHttpSession session)
{
if (_ignoredPaths.Contains(request.Uri.AbsolutePath))
return true;
TextWriter writer = new StreamWriter(response.Body);
try
{
string fileContents = File.ReadAllText("resources" + request.Uri.AbsolutePath);
writer.Write(fileContents);
}
catch (Exception ex)
{
response.ContentType = "text/plain; charset=UTF-8";
writer.WriteLine(ex.Message);
writer.WriteLine(ex.StackTrace);
}
finally
{
writer.Flush();
}
return true;
}
示例10: WriteToOutputStream
public static bool WriteToOutputStream(IHttpResponse response, object result)
{
//var responseStream = response.OutputStream;
var streamWriter = result as IStreamWriter;
if (streamWriter != null)
{
streamWriter.WriteTo(response.OutputStream);
return true;
}
var stream = result as Stream;
if (stream != null)
{
stream.WriteTo(response.OutputStream);
return true;
}
var bytes = result as byte[];
if (bytes != null)
{
response.ContentType = ContentType.Binary;
response.OutputStream.Write(bytes, 0, bytes.Length);
return true;
}
return false;
}
示例11: ApplyResponseBodyFilter
public byte[] ApplyResponseBodyFilter(IHttpResponse response, byte[] body, IEnumerable<Func<IHttpResponse, string, byte[], byte[]>> bodyCallbacks)
{
Contract.Requires(response != null);
Contract.Requires(bodyCallbacks != null);
return null;
}
示例12: ProcessRequest
/// <summary>Enables processing of HTTP Web requests by a custom HttpHandler that implements the <see cref="T:System.Web.IHttpHandler" /> interface.</summary>
///
/// <param name="request"> The request.</param>
/// <param name="response"> The response.</param>
/// <param name="operationName">Name of the operation.</param>
public void ProcessRequest(IHttpRequest request, IHttpResponse response, string operationName)
{
response.ContentType = "text/plain";
response.StatusCode = 403;
response.EndHttpHandlerRequest(skipClose: true, afterBody: r => {
r.Write("Forbidden\n\n");
r.Write("\nRequest.HttpMethod: " + request.HttpMethod);
r.Write("\nRequest.PathInfo: " + request.PathInfo);
r.Write("\nRequest.QueryString: " + request.QueryString);
r.Write("\nRequest.RawUrl: " + request.RawUrl);
if (IsIntegratedPipeline.HasValue)
r.Write("\nApp.IsIntegratedPipeline: " + IsIntegratedPipeline);
if (!WebHostPhysicalPath.IsNullOrEmpty())
r.Write("\nApp.WebHostPhysicalPath: " + WebHostPhysicalPath);
if (!WebHostRootFileNames.IsEmpty())
r.Write("\nApp.WebHostRootFileNames: " + TypeSerializer.SerializeToString(WebHostRootFileNames));
if (!ApplicationBaseUrl.IsNullOrEmpty())
r.Write("\nApp.ApplicationBaseUrl: " + ApplicationBaseUrl);
if (!DefaultRootFileName.IsNullOrEmpty())
r.Write("\nApp.DefaultRootFileName: " + DefaultRootFileName);
if (!DefaultHandler.IsNullOrEmpty())
r.Write("\nApp.DefaultHandler: " + DefaultHandler);
if (!NServiceKitHttpHandlerFactory.DebugLastHandlerArgs.IsNullOrEmpty())
r.Write("\nApp.DebugLastHandlerArgs: " + NServiceKitHttpHandlerFactory.DebugLastHandlerArgs);
});
}
示例13: Replay
public Task Replay(IHttpResponse response)
{
_writes.Each(x => x(response));
return Task.CompletedTask;
}
示例14: Execute
public override void Execute(IHttpRequest req, IHttpResponse res, object requestDto)
{
if (AuthService.AuthProviders == null) throw new InvalidOperationException("The AuthService must be initialized by calling "
+ "AuthService.Init to use an authenticate attribute");
var matchingOAuthConfigs = AuthService.AuthProviders.Where(x =>
this.Provider.IsNullOrEmpty()
|| x.Provider == this.Provider).ToList();
if (matchingOAuthConfigs.Count == 0)
{
res.WriteError(req, requestDto, "No OAuth Configs found matching {0} provider"
.Fmt(this.Provider ?? "any"));
res.Close();
return;
}
AuthenticateIfBasicAuth(req, res);
using (var cache = req.GetCacheClient())
{
var sessionId = req.GetSessionId();
var session = sessionId != null ? cache.GetSession(sessionId) : null;
if (session == null || !matchingOAuthConfigs.Any(x => session.IsAuthorized(x.Provider)))
{
AuthProvider.HandleFailedAuth(matchingOAuthConfigs[0], session, req, res);
}
}
}
示例15: ProcessRequest
/// <summary>
/// Non ASP.NET requests
/// </summary>
/// <param name="request"></param>
/// <param name="response"></param>
/// <param name="operationName"></param>
public void ProcessRequest(IHttpRequest request, IHttpResponse response, string operationName)
{
if (string.IsNullOrEmpty(RelativeUrl) && string.IsNullOrEmpty(AbsoluteUrl))
throw new ArgumentNullException("RelativeUrl or AbsoluteUrl");
if (!string.IsNullOrEmpty(AbsoluteUrl))
{
response.StatusCode = (int)HttpStatusCode.Redirect;
response.AddHeader(HttpHeaders.Location, this.AbsoluteUrl);
}
else
{
var absoluteUrl = request.GetApplicationUrl();
if (!string.IsNullOrEmpty(RelativeUrl))
{
if (this.RelativeUrl.StartsWith("/"))
absoluteUrl = absoluteUrl.CombineWith(this.RelativeUrl);
else if (this.RelativeUrl.StartsWith("~/"))
absoluteUrl = absoluteUrl.CombineWith(this.RelativeUrl.Replace("~/", ""));
else
absoluteUrl = request.AbsoluteUri.CombineWith(this.RelativeUrl);
}
response.StatusCode = (int)HttpStatusCode.Redirect;
response.AddHeader(HttpHeaders.Location, absoluteUrl);
}
response.EndHttpRequest(skipClose:true);
}
开发者ID:grammarware,项目名称:fodder,代码行数:34,代码来源:src_ServiceStack_WebHost_Endpoints_Support_RedirectHttpHandler.cs