本文整理汇总了C#中IHttpResponse.EndRequest方法的典型用法代码示例。如果您正苦于以下问题:C# IHttpResponse.EndRequest方法的具体用法?C# IHttpResponse.EndRequest怎么用?C# IHttpResponse.EndRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IHttpResponse
的用法示例。
在下文中一共展示了IHttpResponse.EndRequest方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public override void Execute(IHttpRequest req, IHttpResponse res, object requestDto)
{
if (AuthenticateService.AuthProviders == null)
throw new InvalidOperationException(
"The AuthService must be initialized by calling AuthService.Init to use an authenticate attribute");
var matchingOAuthConfigs = AuthenticateService.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.EndRequest();
return;
}
if (matchingOAuthConfigs.Any(x => x.Provider == DigestAuthProvider.Name))
AuthenticateIfDigestAuth(req, res);
if (matchingOAuthConfigs.Any(x => x.Provider == BasicAuthProvider.Name))
AuthenticateIfBasicAuth(req, res);
var session = req.GetSession();
if (session == null || !matchingOAuthConfigs.Any(x => session.IsAuthorized(x.Provider)))
{
if (this.DoHtmlRedirectIfConfigured(req, res, true)) return;
AuthProvider.HandleFailedAuth(matchingOAuthConfigs[0], session, req, res);
}
}
示例2: ProcessRequest
/// <summary>
/// This is called by the hosting environment via CatchAll usually for content pages.
/// </summary>
public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
{
httpRes.ContentType = MimeTypes.Html;
ResolveAndExecuteRazorPage(httpReq, httpRes, null);
httpRes.EndRequest(skipHeaders: true);
}
示例3: WriteDebugResponse
public static void WriteDebugResponse(IHttpResponse httpRes, object response)
{
httpRes.WriteToResponse(response, WriteDebugRequest,
new SerializationContext(ContentType.PlainText));
httpRes.EndRequest();
}
示例4: HandleOAuth2Exception
private static void HandleOAuth2Exception(IHttpRequest req, IHttpResponse res, ProtocolFaultResponseException ex) {
var response = ex.CreateErrorResponse();
if (ex.ErrorResponseMessage is UnauthorizedResponse) {
var oauth2Error = ex.ErrorResponseMessage as UnauthorizedResponse;
response.Body = JsonSerializer.SerializeToString(oauth2Error.ToOAuth2JsonResponse());
response.Headers[HttpResponseHeader.ContentType] = "application/json";
}
var context = ((HttpRequest)req.OriginalRequest).RequestContext.HttpContext;
response.Respond(context);
res.EndRequest();
}
示例5: Execute
/// <summary>This method is only executed if the HTTP method matches the <see cref="ApplyTo"/> property.</summary>
///
/// <param name="req"> The http request wrapper.</param>
/// <param name="res"> The http response wrapper.</param>
/// <param name="requestDto">The request DTO.</param>
public override void Execute(IHttpRequest req, IHttpResponse res, object requestDto)
{
base.Execute(req, res, requestDto); //first check if session is authenticated
if (res.IsClosed) return; //AuthenticateAttribute already closed the request (ie auth failed)
var session = req.GetSession();
if (HasAnyPermissions(req, session)) return;
if (DoHtmlRedirectIfConfigured(req, res)) return;
res.StatusCode = (int)HttpStatusCode.Forbidden;
res.StatusDescription = "Invalid Permission";
res.EndRequest();
}
示例6: RequestFilter
public void RequestFilter(IHttpRequest req, IHttpResponse res, object requestDto)
{
if (!string.IsNullOrEmpty(allowedOrigins))
res.AddHeader(HttpHeaders.AllowOrigin, allowedOrigins);
if (!string.IsNullOrEmpty(allowedMethods))
res.AddHeader(HttpHeaders.AllowMethods, allowedMethods);
if (!string.IsNullOrEmpty(allowedHeaders))
res.AddHeader(HttpHeaders.AllowHeaders, allowedHeaders);
if (allowCredentials)
res.AddHeader(HttpHeaders.AllowCredentials, "true");
if (AutoHandleOptionRequests && req.HttpMethod == HttpMethods.Options)
res.EndRequest();
}
示例7: HandleFailedAuth
public static void HandleFailedAuth(IAuthProvider authProvider,
IAuthSession session, IHttpRequest httpReq, IHttpResponse httpRes)
{
var baseAuthProvider = authProvider as AuthProvider;
if (baseAuthProvider != null)
{
baseAuthProvider.OnFailedAuthentication(session, httpReq, httpRes);
return;
}
httpRes.StatusCode = (int)HttpStatusCode.Unauthorized;
httpRes.AddHeader(HttpHeaders.WwwAuthenticate, "{0} realm=\"{1}\""
.Fmt(authProvider.Provider, authProvider.AuthRealm));
httpRes.EndRequest();
}
示例8: OnFailedAuthentication
public virtual void OnFailedAuthentication(IAuthSession session, IHttpRequest httpReq, IHttpResponse httpRes)
{
httpRes.StatusCode = (int)HttpStatusCode.Unauthorized;
httpRes.AddHeader(HttpHeaders.WwwAuthenticate, "{0} realm=\"{1}\"".Fmt(this.Provider, this.AuthRealm));
httpRes.EndRequest();
}
示例9: ProcessRequest
/// <summary>
/// Called by the HtmlFormat:IPlugin who checks to see if any registered view engines can handle the response DTO.
/// If this view engine can handle the response DTO, then process it, otherwise, returning false will
/// allow another view engine to attempt to process it. If no view engines can process the DTO,
/// HtmlFormat will simply handle it itself.
/// </summary>
public virtual bool ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, object dto)
{
//for compatibility
var httpResult = dto as IHttpResult;
if (httpResult != null)
dto = httpResult.Response;
var existingRazorPage = FindRazorPage(httpReq, dto);
if (existingRazorPage == null)
{
return false;
}
ResolveAndExecuteRazorPage(httpReq, httpRes, dto, existingRazorPage);
httpRes.EndRequest();
return true;
}
示例10: ProcessRequest
/// <summary>
/// This is called by the hosting environment via CatchAll usually for content pages.
/// </summary>
public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
{
////ToDo: Figure out binary assets like jpgs and pngs.
httpRes.ContentType = ContentType.PlainText;
if (httpReq.PathInfo.EndsWith("js"))
{
httpRes.ContentType = ContentType.JavaScript;
}
else if (httpReq.PathInfo.EndsWith("css"))
{
httpRes.ContentType = ContentType.css;
}
this.ResolveRazorPageAsset(httpReq, httpRes, null);
httpRes.EndRequest(skipHeaders: true);
}
示例11: HandleException
protected void HandleException(IHttpRequest httpReq, IHttpResponse httpRes, string operationName, Exception ex)
{
var errorMessage = string.Format("Error occured while Processing Request: {0}", ex.Message);
Log.Error(errorMessage, ex);
try
{
EndpointHost.ExceptionHandler(httpReq, httpRes, operationName, 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;
}
finally
{
httpRes.EndRequest(skipHeaders: true);
}
}
示例12: HandleException
protected Task HandleException(IHttpRequest httpReq, IHttpResponse httpRes, string operationName, Exception ex)
{
var errorMessage = string.Format("Error occured while Processing Request: {0}", ex.Message);
Log.Error(errorMessage, ex);
try
{
HostContext.RaiseUncaughtException(httpReq, httpRes, operationName, ex);
return EmptyTask;
}
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
return ex.AsTaskException();
}
finally
{
httpRes.EndRequest(skipHeaders: true);
}
}
示例13: OnFailedAuthentication
public override void OnFailedAuthentication(IAuthSession session, IHttpRequest httpReq, IHttpResponse httpRes)
{
var digestHelper = new DigestAuthFunctions();
httpRes.StatusCode = (int) HttpStatusCode.Unauthorized;
httpRes.AddHeader(
HttpHeaders.WwwAuthenticate,
"{0} realm=\"{1}\", nonce=\"{2}\", qop=\"auth\"".Fmt(Provider, AuthRealm, digestHelper.GetNonce(httpReq.UserHostAddress, PrivateKey)));
httpRes.EndRequest();
}
示例14: ResponseFilter
public void ResponseFilter(IHttpRequest req, IHttpResponse res, object responseDto)
{
using (var ms = new MemoryStream())
{
EndpointHost.ContentTypeFilter.SerializeToStream(
new SerializationContext(req.ResponseContentType), responseDto, ms);
var bytes = ms.ToArray();
var listenerResponse = (HttpListenerResponse)res.OriginalResponse;
listenerResponse.ContentType = "application/json";
listenerResponse.SendChunked = false;
listenerResponse.ContentLength64 = bytes.Length;
listenerResponse.OutputStream.Write(bytes, 0, bytes.Length);
res.EndRequest ();
}
}