本文整理汇总了C#中IHttpResponse.Close方法的典型用法代码示例。如果您正苦于以下问题:C# IHttpResponse.Close方法的具体用法?C# IHttpResponse.Close怎么用?C# IHttpResponse.Close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IHttpResponse
的用法示例。
在下文中一共展示了IHttpResponse.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public override void Execute(IHttpRequest req, IHttpResponse res, object requestDto)
{
var applicationRequest = requestDto as ApplicationRequest;
var appKey = GetAppKeyFromRequest(req, applicationRequest);
var appSecret = GetAppSecretFromRequest(req, applicationRequest);
var app = ApplicationAuthenticationService.Authenticate(appKey,appSecret);
if (app == null)
{
res.StatusCode = (int)HttpStatusCode.Forbidden;
// Some Android devices require a body, otherwise the response code is ignored and set 0
res.Write(HttpStatusCode.Forbidden.ToString());
res.Close();
}
if (applicationRequest != null)
{
applicationRequest.AppKey = appKey;
applicationRequest.AppSecret = appSecret;
applicationRequest.Application = ApplicationRepository.FindApplication(appKey, appSecret);
applicationRequest.Account = AccountApplicationRepository.GetForApplication(applicationRequest.Application.Id);
}
var validationErrors = ValidateRequest(applicationRequest);
if (validationErrors.Any())
{
res.StatusCode = (int)HttpStatusCode.BadRequest;
// Some Android devices require a body, otherwise the response code is ignored and set 0
res.Write(HttpStatusCode.BadRequest.ToString());
foreach (var error in validationErrors)
{
res.Write(error);
}
res.Close();
}
}
示例2: WriteDebugResponse
public static void WriteDebugResponse(IHttpResponse httpRes, object response)
{
httpRes.WriteToResponse(response, WriteDebugRequest,
new SerializationContext(ContentType.PlainText));
httpRes.Close();
}
示例3: WriteDebugResponse
public static void WriteDebugResponse(IHttpResponse httpRes, object response)
{
httpRes.WriteToResponse(response, WriteDebugRequest,
new SerializationContext(ContentType.PlainText));
ServiceStack.WebHost.Endpoints.EndpointHost.AddGlobalResponseHeaders(httpRes);
httpRes.Close();
}
示例4: Execute
public override void Execute(IHttpRequest req, IHttpResponse res, object requestDto)
{
AuthenticateAttribute.AuthenticateIfBasicAuth(req, res);
var session = req.GetSession();
if (HasAllRoles(req, session)) return;
res.StatusCode = (int)HttpStatusCode.Unauthorized;
res.StatusDescription = "Invalid Role";
res.Close();
}
示例5: Execute
public override void Execute(IHttpRequest req, IHttpResponse res, object requestDto)
{
AuthenticateAttribute.AuthenticateIfBasicAuth(req, res);
var session = req.GetSession();
if (HasAllPermissions(req, session)) return;
res.StatusCode = (int)HttpStatusCode.Unauthorized;
res.StatusDescription = "Invalid Permissions";
ServiceStack.WebHost.Endpoints.EndpointHost.AddGlobalResponseHeaders(res);
res.Close();
}
示例6: Execute
public override void Execute(IHttpRequest req, IHttpResponse res, object requestDto)
{
var session = req.GetSession();
foreach (string requiredPermission in this.RequiredPermissions)
{
if (session == null || !session.HasPermission(requiredPermission))
{
res.StatusCode = (int)HttpStatusCode.Unauthorized;
res.StatusDescription = "Invalid Permissions";
res.Close();
return;
}
}
}
示例7: ProcessRequest
public void ProcessRequest(IHttpRequest request, IHttpResponse response, string operationName)
{
var text = new StringBuilder("Handler for Request not found: \n\n")
.AppendLine("Request.HttpMethod: " + request.HttpMethod)
.AppendLine("Request.HttpMethod: " + request.HttpMethod)
.AppendLine("Request.PathInfo: " + request.PathInfo)
.AppendLine("Request.QueryString: " + request.QueryString)
.AppendLine("Request.RawUrl: " + request.RawUrl).ToString();
response.ContentType = "text/plain";
response.StatusCode = 404;
response.Write(text);
response.Close();
}
示例8: ProcessRequest
public void ProcessRequest(IHttpRequest request, IHttpResponse response, string operationName)
{
Log.ErrorFormat("{0} Request not found: {1}", request.UserHostAddress, request.RawUrl);
var text = new StringBuilder("Handler for Request not found: \n\n")
.AppendLine("Request.HttpMethod: " + request.HttpMethod)
.AppendLine("Request.HttpMethod: " + request.HttpMethod)
.AppendLine("Request.PathInfo: " + request.PathInfo)
.AppendLine("Request.QueryString: " + request.QueryString)
.AppendLine("Request.RawUrl: " + request.RawUrl).ToString();
response.ContentType = "text/plain";
response.StatusCode = 404;
response.Write(text);
ServiceStack.WebHost.Endpoints.EndpointHost.AddGlobalResponseHeaders(response);
response.Close();
}
示例9: 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.AbsoluteUri.WithTrailingSlash() + this.RelativeUrl;
response.StatusCode = (int)HttpStatusCode.Redirect;
response.AddHeader(HttpHeaders.Location, absoluteUrl);
}
response.Close();
}
示例10: Execute
public override void Execute(IHttpRequest req, IHttpResponse res, object requestDto)
{
if (AuthService.AuthConfigs == null) throw new InvalidOperationException("The AuthService must be initialized by calling "
+ "AuthService.Init to use an authenticate attribute");
var matchingOAuthConfigs = AuthService.AuthConfigs.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;
}
var userPass = req.GetBasicAuthUserAndPassword();
if (userPass != null)
{
var authService = req.TryResolve<AuthService>();
authService.RequestContext = new HttpRequestContext(req, res, requestDto);
var response = authService.Post(new Auth.Auth {
provider = BasicAuthConfig.Name,
UserName = userPass.Value.Key,
Password = userPass.Value.Value
});
}
using (var cache = req.GetCacheClient())
{
var sessionId = req.GetPermanentSessionId();
var session = sessionId != null ? cache.GetSession(sessionId) : null;
if (session == null || !matchingOAuthConfigs.Any(x => session.IsAuthorized(x.Provider)))
{
res.StatusCode = (int)HttpStatusCode.Unauthorized;
res.AddHeader(HttpHeaders.WwwAuthenticate, "{0} realm=\"{1}\""
.Fmt(matchingOAuthConfigs[0].Provider, matchingOAuthConfigs[0].AuthRealm));
res.Close();
}
}
}
示例11: ProcessRequest
public void ProcessRequest(IHttpRequest request, IHttpResponse response, string operationName)
{
var resourceName = string.Concat(_assembly.GetName().Name, ".", _filePath.Replace('/', '.'));
response.ContentType = MimeTypes.GetMimeType(_filePath);
using(var stream = _assembly.GetManifestResourceStream(resourceName))
{
if (stream == null)
{
response.StatusCode = (int)HttpStatusCode.NotFound;
response.Close();
}
else
{
// TODO: Figure out the best way to enable browser caching of this static content.
response.AddHeader(HttpHeaders.CacheControl, "max-age=" + TimeSpan.FromDays(5).TotalSeconds);
response.SetContentLength(stream.Length);
stream.CopyTo(response.OutputStream);
response.OutputStream.Flush();
}
}
}
示例12: 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.Close();
}
示例13: 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.Close();
}
示例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;
}
AuthenticateIfDigestAuth(req, res);
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
public void ProcessRequest(IHttpRequest request, IHttpResponse response, string operationName)
{
ServiceStack.WebHost.Endpoints.EndpointHost.AddGlobalResponseHeaders(response);
var fileName = request.GetPhysicalPath();
var fi = new FileInfo(fileName);
if (!fi.Exists)
{
if ((fi.Attributes & FileAttributes.Directory) != 0)
{
foreach (var defaultDoc in EndpointHost.Config.DefaultDocuments)
{
var defaultFileName = Path.Combine(fi.FullName, defaultDoc);
if (!File.Exists(defaultFileName)) continue;
response.Redirect(request.GetPathUrl() + '/' + defaultDoc);
return;
}
}
if (!fi.Exists)
throw new HttpException(404, "File '" + request.PathInfo + "' not found.");
}
TimeSpan maxAge;
if (response.ContentType != null && EndpointHost.Config.AddMaxAgeForStaticMimeTypes.TryGetValue(response.ContentType, out maxAge))
{
response.AddHeader(HttpHeaders.CacheControl, "max-age=" + maxAge.TotalSeconds);
}
if (request.HasNotModifiedSince(fi.LastWriteTime))
{
response.ContentType = MimeTypes.GetMimeType(fileName);
response.StatusCode = 304;
return;
}
try
{
response.AddHeaderLastModified(fi.LastWriteTime);
response.ContentType = MimeTypes.GetMimeType(fileName);
if (fileName.EqualsIgnoreCase(this.DefaultFilePath))
{
if (fi.LastWriteTime > this.DefaultFileModified)
SetDefaultFile(this.DefaultFilePath); //reload
response.OutputStream.Write(this.DefaultFileContents, 0, this.DefaultFileContents.Length);
response.Close();
return;
}
if (!Env.IsMono)
{
response.TransmitFile(fileName);
}
else
{
response.WriteFile(fileName);
}
}
catch (Exception)
{
throw new HttpException(403, "Forbidden.");
}
}