本文整理汇总了C#中IResponse.EndRequest方法的典型用法代码示例。如果您正苦于以下问题:C# IResponse.EndRequest方法的具体用法?C# IResponse.EndRequest怎么用?C# IResponse.EndRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IResponse
的用法示例。
在下文中一共展示了IResponse.EndRequest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessRequest
/// <summary>
/// This is called by the hosting environment via CatchAll usually for content pages.
/// </summary>
public override void ProcessRequest(IRequest httpReq, IResponse httpRes, string operationName)
{
httpRes.ContentType = MimeTypes.Html;
ResolveAndExecuteRazorPage(httpReq, httpRes, null);
httpRes.EndRequest(skipHeaders: true);
}
示例2: Execute
public override void Execute(IRequest req, IResponse res, object requestDto)
{
if (HostContext.HasValidAuthSecret(req))
return;
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();
var authRepo = HostContext.AppHost.GetAuthRepository(req);
using (authRepo as IDisposable)
{
if (session != null && session.HasRole(RoleNames.Admin, authRepo))
return;
if (HasAnyPermissions(req, session, authRepo)) return;
}
if (DoHtmlRedirectIfConfigured(req, res)) return;
res.StatusCode = (int)HttpStatusCode.Forbidden;
res.StatusDescription = ErrorMessages.InvalidPermission;
res.EndRequest();
}
示例3: Execute
public override void Execute(IRequest req, IResponse res, object requestDto)
{
if (AuthenticateService.AuthProviders == null)
throw new InvalidOperationException(
"The AuthService must be initialized by calling AuthService.Init to use an authenticate attribute");
if (HostContext.HasValidAuthSecret(req))
return;
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 {this.Provider ?? "any"} provider");
res.EndRequest();
return;
}
req.PopulateFromRequestIfHasSessionId(requestDto);
//Call before GetSession so Exceptions can bubble
req.Items[Keywords.HasPreAuthenticated] = true;
matchingOAuthConfigs.OfType<IAuthWithRequest>()
.Each(x => x.PreAuthenticate(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);
}
}
示例4: Execute
public override void Execute(IRequest req, IResponse 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);
}
}
示例5: Execute
public override void Execute(IRequest req, IResponse 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: Execute
public override void Execute(IRequest req, IResponse res, object requestDto)
{
if (SkipIfDebugMode && HostContext.Config.DebugMode)
return;
if (!req.IsSecureConnection)
{
if (SkipIfXForwardedFor)
{
var httpReq = req as IHttpRequest;
if (httpReq != null && httpReq.XForwardedFor != null)
return;
}
res.RedirectToUrl(req.AbsoluteUri.AsHttps());
res.EndRequest();
}
}
示例7: Execute
public override void Execute(IRequest req, IResponse res, object requestDto)
{
if (HostContext.AppHost.HasValidAuthSecret(req))
return;
base.Execute(req, res, requestDto);
if (res.IsClosed)
return;
var session = req.GetSession();
if (session != null && session.HasRole("Admin")
|| (this.HasWebSudo(req, session as IWebSudoAuthSession)
|| this.DoHtmlRedirectIfConfigured(req, res)))
return;
res.StatusCode = 402;
res.StatusDescription = "Web Sudo Required";
res.EndRequest();
}
示例8: Execute
public override void Execute(IRequest req, IResponse res, object requestDto)
{
if (HostContext.AppHost.HasValidAuthSecret(req))
return;
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 (session != null && session.HasRole(RoleNames.Admin))
return;
if (HasAllRoles(req, session)) return;
if (DoHtmlRedirectIfConfigured(req, res)) return;
res.StatusCode = (int)HttpStatusCode.Forbidden;
res.StatusDescription = "Invalid Role";
res.EndRequest();
}
示例9: HandleException
protected Task HandleException(IRequest httpReq, IResponse httpRes, string operationName, Exception ex)
{
var errorMessage = $"Error occured while Processing Request: {ex.Message}";
HostContext.AppHost.OnLogError(typeof(HttpAsyncTaskHandler), errorMessage, ex);
try
{
HostContext.RaiseAndHandleUncaughtException(httpReq, httpRes, operationName, ex);
return TypeConstants.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);
}
}
示例10: OnFailedAuthentication
public virtual void OnFailedAuthentication(IAuthSession session, IRequest httpReq, IResponse httpRes)
{
httpRes.StatusCode = (int)HttpStatusCode.Unauthorized;
httpRes.AddHeader(HttpHeaders.WwwAuthenticate, "{0} realm=\"{1}\"".Fmt(this.Provider, this.AuthRealm));
httpRes.EndRequest();
}
示例11: HandleFailedAuth
public static void HandleFailedAuth(IAuthProvider authProvider,
IAuthSession session, IRequest httpReq, IResponse 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();
}
示例12: OnFailedAuthentication
public override void OnFailedAuthentication(IAuthSession session, IRequest httpReq, IResponse 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();
}
示例13: HandleException
protected Task HandleException(IRequest httpReq, IResponse 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);
}
}
示例14: ProcessRequest
/// <summary>
/// This is called by the hosting environment via CatchAll usually for content pages.
/// </summary>
public override void ProcessRequest(IRequest httpReq, IResponse httpRes, string operationName)
{
HostContext.ApplyCustomHandlerRequestFilters(httpReq, httpRes);
if (httpRes.IsClosed) return;
httpRes.ContentType = MimeTypes.Html;
var contentPage = ResolveContentPage(httpReq);
using (ExecuteRazorPage(httpReq, httpRes, null, contentPage))
{
httpRes.EndRequest(skipHeaders: true);
}
}
示例15: OnFailedAuthentication
public override void OnFailedAuthentication(IAuthSession session, IRequest httpReq, IResponse httpRes)
{
httpRes.StatusCode = (int)HttpStatusCode.Unauthorized;
//Needs to be 'Basic ' in order for HttpWebRequest to accept challenge and send NetworkCredentials
httpRes.AddHeader(HttpHeaders.WwwAuthenticate, $"Basic realm=\"{this.AuthRealm}\"");
httpRes.EndRequest();
}