本文整理汇总了C#中IHttpResponse.AddHeader方法的典型用法代码示例。如果您正苦于以下问题:C# IHttpResponse.AddHeader方法的具体用法?C# IHttpResponse.AddHeader怎么用?C# IHttpResponse.AddHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IHttpResponse
的用法示例。
在下文中一共展示了IHttpResponse.AddHeader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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.GetApplicationUrl();
if (!string.IsNullOrEmpty(RelativeUrl))
{
if (this.RelativeUrl.StartsWith("/"))
absoluteUrl = absoluteUrl.CombineWith(this.RelativeUrl);
else if (this.RelativeUrl.StartsWith("~/"))
absoluteUrl = absoluteUrl.CombineWith(this.RelativeUrl.Replace("~/", ""));
else
absoluteUrl = request.AbsoluteUri.CombineWith(this.RelativeUrl);
}
response.StatusCode = (int)HttpStatusCode.Redirect;
response.AddHeader(HttpHeaders.Location, absoluteUrl);
}
response.EndHttpRequest(skipClose:true);
}
开发者ID:grammarware,项目名称:fodder,代码行数:34,代码来源:src_ServiceStack_WebHost_Endpoints_Support_RedirectHttpHandler.cs
示例2: ResponseFilter
public void ResponseFilter(IHttpRequest req, IHttpResponse res, object response)
{
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");
}
示例3: RequestFilter
/// <summary>The request filter is executed before the service.</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 void RequestFilter(IHttpRequest req, IHttpResponse res, object requestDto)
{
if (applyWhere != null && !applyWhere(req, requestDto))
return;
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");
}
示例4: 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();
}
示例5: OpenSearchDescriptionSerializer
public static void OpenSearchDescriptionSerializer(IRequestContext reqCtx, object res, IHttpResponse stream)
{
stream.AddHeader("Content-Encoding",Encoding.Default.EncodingName);
using(XmlWriter writer = XmlWriter.Create(stream.OutputStream, new XmlWriterSettings() { OmitXmlDeclaration = false, Encoding = Encoding.Default }))
{
new System.Xml.Serialization.XmlSerializer(res.GetType()).Serialize(writer, res);
}
}
示例6: ProcessRequest
/// <summary>
/// Non ASP.NET requests
/// </summary>
public override void ProcessRequest(IHttpRequest request, IHttpResponse response, string operationName)
{
var defaultUrl = HostContext.Config.ServiceEndpointsMetadataConfig.DefaultMetadataUri;
if (request.PathInfo == "/")
{
var relativeUrl = defaultUrl.Substring(defaultUrl.IndexOf('/'));
var absoluteUrl = request.RawUrl.TrimEnd('/') + relativeUrl;
response.StatusCode = (int) HttpStatusCode.Redirect;
response.AddHeader(HttpHeaders.Location, absoluteUrl);
}
else
{
response.StatusCode = (int)HttpStatusCode.Redirect;
response.AddHeader(HttpHeaders.Location, defaultUrl);
}
}
示例7: 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();
}
示例8: OptionsHandler
void OptionsHandler(IHttpClientContext context, IHttpRequest request, IHttpResponse response)
{
response.AddHeader("DAV", "2");
response.AddHeader("MS-Author-Via", "DAV");
//This now gets all the events that have handler from the dav listener
string allowString = server.GetAvailableMethods();
//Add this information to both, Public and Allow. We currently have no way of separating these two
response.AddHeader("Public", allowString);
response.AddHeader("Allow", allowString);
//Preserving the old headers as reference. These should be removed when method is mature enough
//response.AddHeader("Public", "COPY, DELETE, GET, HEAD, MKCOL, MOVE, OPTIONS, PROPFIND, PROPPATCH, PUT");
//response.AddHeader("Allow", "COPY, DELETE, GET, HEAD, MKCOL, MOVE, OPTIONS, PROPFIND, PROPPATCH, PUT");
server.HttpServer.LogWriter.Write(this, LogPrio.Debug, "Sending OPTIONS response for request to " + request.UriPath);
}
示例9: Execute
public override void Execute(IHttpRequest req, IHttpResponse res, object requestDto)
{
if (string.IsNullOrEmpty(Name) || string.IsNullOrEmpty(Value)) return;
if (Name.Equals(HttpHeaders.ContentType, StringComparison.InvariantCultureIgnoreCase))
{
res.ContentType = Value;
}
else
{
res.AddHeader(Name, Value);
}
}
示例10: Process
public override bool Process(IHttpRequest request, IHttpResponse response, IHttpSession session)
{
_log.Write(this, LogPrio.Trace, String.Format("Begin handling Rack request for {0}", request.Uri));
var rackRequest = request.ToRackRequest();
var rackResponse = new RackResponse(response.Body);
//this will write to the body. We may want to set headers first, so may need some thought.
_rack.HandleRequest(rackRequest, rackResponse);
response.Status = (HttpStatusCode)rackResponse.Status;
foreach (var header in rackResponse.Headers)
if (header.Key.ToLower() != "content-length")
response.AddHeader(header.Key, header.Value);
_log.Write(this, LogPrio.Trace, String.Format("Finished handling Rack request for {0}", request.Uri));
return true;
}
示例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: Execute
public override void Execute(IHttpRequest req, IHttpResponse res, object requestDto)
{
if (StatusCode != null)
{
res.StatusCode = StatusCode.Value;
}
if (StatusDescription != null)
{
res.StatusDescription = StatusDescription;
}
if (!string.IsNullOrEmpty(Name) && !string.IsNullOrEmpty(Value))
{
if (Name.Equals(HttpHeaders.ContentType, StringComparison.InvariantCultureIgnoreCase))
{
res.ContentType = Value;
}
else
{
res.AddHeader(Name, Value);
}
}
}
示例13: Process
public override bool Process(IHttpRequest request, IHttpResponse response, IHttpSession session)
{
try
{
if (!CanHandle(request.Uri))
{
return false;
}
response.Encoding = Encoding.UTF8;
var command = Path.GetFileName(request.Uri.AbsolutePath);
Func handler;
if (OBBContext.Current.IsMaster)
{
if (!masterHandlers.TryGetValue(command, out handler))
{
response.Status = HttpStatusCode.NotFound;
return false;
}
}
else
{
if (!slaveHandlers.TryGetValue(command, out handler))
{
response.Status = HttpStatusCode.NotFound;
return false;
}
}
response.AddHeader("Cache-Control", "no-cache");
response.AddHeader("Pragma", "no-cache");
response.AddHeader("Expires", "0");
if (!handler(request, response))
return false;
return true;
}
catch (Exception ex)
{
Debug.WriteLine(ex);
return false;
}
}
示例14: CreateChallenge
/// <summary>
/// Create a WWW-Authenticate header
/// </summary>
public void CreateChallenge(IHttpRequest httpRequest, IHttpResponse response)
{
response.AddHeader("WWW-Authenticate", "Basic realm=\"" + _realm + "\"");
response.StatusCode = 401;
}
示例15: Process
//.........这里部分代码省略.........
{
throw new ForbiddenException("Directory listing not allowed");
}
string output = GetDirectoryListing(path, request.Uri);
response.ContentType = "text/html";
response.ContentLength = output.Length;
response.SendHeaders();
response.SendBody(System.Text.Encoding.Default.GetBytes(output));
return true;
}
}
if (extension == null && file_exists) extension = "default";
if (!MimeTypes.ContainsKey(extension))
{
if (_serveUnknownTypes)
{
extension = "default";
}
else throw new ForbiddenException("Forbidden file type: " + extension);
}
// Cgi file
if (MimeTypes[extension].Equals("wwwserver/stdcgi"))
{
if (!_cgiApplications.ContainsKey(extension))
throw new ForbiddenException("Unknown cgi file type: " + extension);
if (!File.Exists(_cgiApplications[extension]))
throw new InternalServerException("Cgi executable not found: " + _cgiApplications[extension]);
string output = CGI.Execute(_cgiApplications[extension], path, request);
response.ContentType = "text/html";
GetCgiHeaders(ref output, response);
response.ContentLength = output.Length;
response.SendHeaders();
response.SendBody(Encoding.Default.GetBytes(output));
}
else // other files
{
response.ContentType = MimeTypes[extension];
using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
if (!string.IsNullOrEmpty(request.Headers["if-Modified-Since"]))
{
DateTime lastRequest = DateTime.Parse(request.Headers["if-Modified-Since"]);
if (lastRequest.CompareTo(File.GetLastWriteTime(path)) <= 0)
response.Status = HttpStatusCode.NotModified;
}
if (_useLastModifiedHeader)
response.AddHeader("Last-modified", File.GetLastWriteTime(path).ToString("r"));
response.ContentLength = stream.Length;
response.SendHeaders();
if (request.Method != "Headers" && response.Status != HttpStatusCode.NotModified)
{
byte[] buffer = new byte[8192];
int bytesRead = stream.Read(buffer, 0, 8192);
while (bytesRead > 0)
{
response.SendBody(buffer, 0, bytesRead);
bytesRead = stream.Read(buffer, 0, 8192);
}
}
}
}
}
catch (InternalServerException err)
{
throw err;
}
catch (ForbiddenException err)
{
throw err;
}
catch (NotFoundException err)
{
throw err;
}
catch (FileNotFoundException err)
{
throw new NotFoundException("Failed to proccess file: " + request.Uri.LocalPath, err);
}
catch (Exception err)
{
throw new InternalServerException("Internal server error [FileModule]", err);
}
return true;
}