本文整理汇总了C#中IResponse.WriteError方法的典型用法代码示例。如果您正苦于以下问题:C# IResponse.WriteError方法的具体用法?C# IResponse.WriteError怎么用?C# IResponse.WriteError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IResponse
的用法示例。
在下文中一共展示了IResponse.WriteError方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
示例2: 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);
}
}