本文整理汇总了C#中IResponse.Close方法的典型用法代码示例。如果您正苦于以下问题:C# IResponse.Close方法的具体用法?C# IResponse.Close怎么用?C# IResponse.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IResponse
的用法示例。
在下文中一共展示了IResponse.Close方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public override void Execute(IRequest req, IResponse res, object requestDto)
{
var authErrorMessage = "";
try
{
// Perform security check
if (CanExecute(req))
return;
}
catch (System.Exception ex)
{
authErrorMessage = ex.Message;
var message = string.Format("Blocked unauthorized request: {0} {1} by ip = {2} due to {3}",
req.Verb,
req.AbsoluteUri,
req.UserHostAddress ?? "unknown",
authErrorMessage);
Log.Error(message);
}
// Security failed!
var responseMessage = "You are not authorized. " + authErrorMessage;
res.StatusCode = (int)HttpStatusCode.Unauthorized;
res.StatusDescription = responseMessage;
res.AddHeader(HttpHeaders.WwwAuthenticate, string.Format("{0} realm=\"{1}\"", "", "custom api"));
res.ContentType = "text/plain";
res.Write(responseMessage);
res.Close();
}
示例2: ProcessResult
private void ProcessResult(IResponse response, RateLimitResult rateLimitResult)
{
SetLimitHeaders(response, rateLimitResult);
// NOTE By default we return an empty RateLimitResult which will have an 'Access' value of null.. which we default to true. Is this correct?
if (!rateLimitResult?.Access ?? true)
{
if (log.IsDebugEnabled)
{
var request = response.Request;
log.Debug(
$"Rate limit exceeded for {request.AbsoluteUri}, user {KeyGenerator.GetConsumerId(request)}. Returning status code: {LimitStatusCode}");
}
response.StatusCode = LimitStatusCode;
response.StatusDescription = StatusDescription;
response.Close();
}
}