本文整理汇总了C#中HttpResponse.AddHeader方法的典型用法代码示例。如果您正苦于以下问题:C# HttpResponse.AddHeader方法的具体用法?C# HttpResponse.AddHeader怎么用?C# HttpResponse.AddHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpResponse
的用法示例。
在下文中一共展示了HttpResponse.AddHeader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ResponseFile
public bool ResponseFile(HttpRequest _Request, HttpResponse _Response, string _fileName, string _fullUrl, long _speed)
{
try
{
FileStream myFile = new FileStream(_fullUrl, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
BinaryReader br = new BinaryReader(myFile);
try
{
_Response.AddHeader("Accept-Ranges", "bytes");
_Response.Buffer = false;
long fileLength = myFile.Length;
long startBytes = 0;
int pack = 10240; //10K bytes
int sleep = (int)Math.Floor((double)(1000 * pack / _speed)) + 1;
if (_Request.Headers["Range"] != null)
{
_Response.StatusCode = 206;
string[] range = _Request.Headers["Range"].Split(new char[] { '=', '-' });
startBytes = Convert.ToInt64(range[1]);
}
_Response.AddHeader("Content-Length", (fileLength - startBytes).ToString());
if (startBytes != 0)
{
_Response.AddHeader("Content-Range", string.Format(" bytes {0}-{1}/{2}", startBytes, fileLength - 1, fileLength));
}
_Response.AddHeader("Connection", "Keep-Alive");
_Response.ContentType = "application/octet-stream";
_Response.AddHeader("Content-Disposition", "attachment;filename="
+ HttpUtility.UrlEncode(_fileName, System.Text.Encoding.UTF8));
br.BaseStream.Seek(startBytes, SeekOrigin.Begin);
int maxCount = (int)Math.Floor((double)((fileLength - startBytes) / pack)) + 1;
for (int i = 0; i < maxCount; i++)
{
if (_Response.IsClientConnected)
{
_Response.BinaryWrite(br.ReadBytes(pack));
Thread.Sleep(sleep);
}
else
{
i = maxCount;
}
}
}
catch
{
return false;
}
finally
{
br.Close();
myFile.Close();
}
}
catch
{
return false;
}
return true;
}
示例2: GetResponse
public HttpResponse GetResponse()
{
var response = new HttpResponse(Request.ProtocolVersion, GetStatusCode(), GetContent(), HighQualityCodeExamPointsProvider.GetContentType());
foreach (var responseHeader in ResponseHeaders)
{
response.AddHeader(responseHeader.Key, responseHeader.Value);
}
return response;
}
示例3: GetResponse
public HttpResponse GetResponse()
{
var response = new HttpResponse(this.Request.ProtocolVersion, HttpStatusCode.OK, this.model.ToString(), ContentType);
foreach (var responseHeader in this.ResponseHeaders)
{
response.AddHeader(responseHeader.Key, responseHeader.Value);
}
return response;
}
示例4: GetResponse
/// <summary>
/// The get response.
/// </summary>
/// <returns>
/// The <see cref="HttpResponse" />.
/// </returns>
public HttpResponse GetResponse()
{
var response = new HttpResponse(this.Request.ProtocolVersion, HttpStatusCode.Redirect, string.Empty);
foreach (var responseHeader in this.ResponseHeaders)
{
response.AddHeader(responseHeader.Key, responseHeader.Value);
}
return response;
}
示例5: GetResponse
public HttpResponse GetResponse()
{
var response = new HttpResponse(this.Request.ProtocolVersion, this.GetStatusCode(), this.GetContent(), this.GetContentType());
foreach (var responseHeader in this.ResponseHeaders)
{
response.AddHeader(responseHeader.Key, responseHeader.Value);
}
return response;
}
示例6: ExportCSV
protected static void ExportCSV(HttpResponse response, string fileText, string fileName)
{
byte[] buffer = GetBytes(fileText);
try
{
response.Clear();
response.ContentType = "text/plain";
response.OutputStream.Write(buffer, 0, buffer.Length);
response.AddHeader("Content-Disposition", "attachment;filename=\"" + fileName + "\"");
response.End();
}
catch (System.Web.HttpException ex)
{
// ignore exception where user closed the download box
if (!ex.Message.StartsWith("The remote host closed the connection. The error code is"))
throw;
}
}
示例7: NotifyServerCallExit
internal void NotifyServerCallExit(HttpResponse response) {
try {
if (NotifySink == null) return;
IntPtr bufferPtr;
int bufferSize = 0;
CallId callId = new CallId(null, 0, (IntPtr)0, 0, null, null);
TraceMethod method = Tracing.On ? new TraceMethod(this, "NotifyServerCallExit") : null;
if (Tracing.On) Tracing.Enter("RemoteDebugger", method);
UnsafeNativeMethods.OnSyncCallExit(NotifySink, callId, out bufferPtr, ref bufferSize);
if (Tracing.On) Tracing.Exit("RemoteDebugger", method);
if (bufferPtr == IntPtr.Zero) return;
byte[] buffer = null;
try {
buffer = new byte[bufferSize];
Marshal.Copy(bufferPtr, buffer, 0, bufferSize);
}
finally {
Marshal.FreeCoTaskMem(bufferPtr);
}
string stringBuffer = Convert.ToBase64String(buffer);
response.AddHeader(debuggerHeader, stringBuffer);
}
catch (Exception e) {
if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) {
throw;
}
if (Tracing.On) Tracing.ExceptionCatch(TraceEventType.Warning, typeof(RemoteDebugger), "NotifyServerCallExit", e);
}
this.Close();
}
示例8: Process
/// <summary>
/// Method that process the url
/// </summary>
/// <param name="request">Information sent by the browser about the request</param>
/// <param name="response">Information that is being sent back to the client.</param>
/// <param name="session">Session used to </param>
/// <returns>true if this module handled the request.</returns>
public override bool Process(HttpRequest request, HttpResponse response, IHttpSession session)
{
if(!CanHandle(request))
return false;
string path = request.Uri.AbsolutePath;
string contentType;
Stream resourceStream = GetResourceStream(path, out contentType);
if(resourceStream == null)
return false;
response.ContentType = contentType;
DateTime modifiedTime = DateTime.MinValue;
if (!string.IsNullOrEmpty(request.Headers["if-modified-since"]))
{
DateTime lastRequest = DateTime.Parse(request.Headers["if-modified-since"]);
if (lastRequest.CompareTo(modifiedTime) <= 0)
response.Status = HttpStatusCode.NotModified;
}
response.AddHeader("Last-modified", modifiedTime.ToString("r"));
response.ContentLength = resourceStream.Length;
response.SendHeaders();
if (request.Method != "Headers" && response.Status != HttpStatusCode.NotModified)
{
byte[] buffer = new byte[8192];
int bytesRead = resourceStream.Read(buffer, 0, 8192);
while (bytesRead > 0)
{
response.SendBody(buffer, 0, bytesRead);
bytesRead = resourceStream.Read(buffer, 0, 8192);
}
}
return true;
}
示例9: DownloadDocument
public static void DownloadDocument(HttpResponse httpResponse, byte[] fileContents, string fileName)
{
try
{
string contentType = "application/octet-stream";
try { contentType = Utilities.GetMimeType(System.IO.Path.GetExtension(fileName)); }
catch (Exception) { }
httpResponse.Clear();
httpResponse.ClearHeaders();
// add cooke so that javascript can detect when file downloaded is done and started if it want's to
// do something (such as letter print page to deselect leter to print)
httpResponse.Cookies["fileDownloaded"].Value = "true";
httpResponse.Cookies["fileDownloaded"].Expires = DateTime.Now.AddHours(3);
httpResponse.ContentType = contentType;
httpResponse.AddHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
httpResponse.OutputStream.Write(fileContents, 0, fileContents.Length);
httpResponse.Flush();
httpResponse.End();
}
catch (System.Web.HttpException ex)
{
// ignore exception where user closed the download box
if (!ex.Message.StartsWith("The remote host closed the connection. The error code is"))
throw;
}
}
示例10: UpdateResponse
protected override void UpdateResponse(HttpResponse response)
{
response.AddHeader("Access-Control-Allow-Origin", this.corsSettings);
}
示例11: AddHeader
/// <summary>
/// Adds an HTTP Response Header
/// </summary>
/// <remarks>
/// This method is used to store the Response Headers in a private, member variable,
/// InternalResponseHeaders, so that the Response Headers may be accesed in the
/// LogResponseHttpHeaders method, if needed. The Response.Headers property can only
/// be accessed directly when using IIS 7's Integrated Pipeline mode. This workaround
/// permits logging of Response Headers when using Classic mode or a web server other
/// than IIS 7.
/// </remarks>
protected void AddHeader(HttpResponse response, string name, string value)
{
//_internalResponseHeaders.Add(name, value);
response.AddHeader(name, value);
}
示例12: Process
/// <summary>
/// Method that process the Uri.
/// </summary>
/// <param name="request">Information sent by the browser about the request</param>
/// <param name="response">Information that is being sent back to the client.</param>
/// <param name="session">Session used to </param>
/// <exception cref="InternalServerException">Failed to find file extension</exception>
/// <exception cref="ForbiddenException">File type is forbidden.</exception>
public override bool Process(HttpRequest request, HttpResponse response, IHttpSession session)
{
if (!CanHandle(request.Uri))
return false;
try
{
string path = GetPath(request.Uri);
string extension = GetFileExtension(path);
if (extension == null)
throw new InternalServerException("Failed to find file extension");
if (MimeTypes.ContainsKey(extension))
response.ContentType = MimeTypes[extension];
else
throw new ForbiddenException("Forbidden file type: " + 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 (FileNotFoundException err)
{
throw new InternalServerException("Failed to proccess file.", err);
}
return true;
}
示例13: UpdateResponse
protected override void UpdateResponse(HttpResponse response)
{
response.AddHeader("Cache-Control", "private, max-age=0, no-cache");
}
示例14: ExportToCSV
private void ExportToCSV(string exportContent, HttpResponse response)
{
response.Clear();
response.AddHeader("content-disposition", "attachment;filename=" + fileName);
response.Charset = "";
response.ContentType = "application/octet-stream";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
response.Write(exportContent);
response.End();
}
示例15: Write
public void Write(HttpResponse response, bool inline)
{
response.Clear();
response.ContentType = "application/pdf";
response.AddHeader("Content-Disposition", (inline ? "inline" : "attachment") + "; filename=Map.pdf");
// create the PDF document
Configuration config = AppContext.GetConfiguration();
Configuration.PrintTemplateRow printTemplate = config.PrintTemplate.First(o => o.TemplateID == _templateId);
float pageWidth = Convert.ToSingle(printTemplate.PageWidth * PointsPerInch);
float pageHeight = Convert.ToSingle(printTemplate.PageHeight * PointsPerInch);
Rectangle pageSize = new Rectangle(pageWidth, pageHeight);
pageSize.BackgroundColor = new Color(System.Drawing.Color.White);
Document document = new Document(pageSize);
PdfWriter writer = PdfWriter.GetInstance(document, response.OutputStream);
document.Open();
PdfContentByte content = writer.DirectContent;
// get the extent of the main map and fit it to the proportions of
// the map box on the page
double mapScale = 0;
Configuration.PrintTemplateContentRow mapElement = printTemplate.GetPrintTemplateContentRows().FirstOrDefault(o => o.ContentType == "map");
if (mapElement != null)
{
if (_preserveMode == PreserveMode.Extent)
{
_appState.Extent.Reaspect(mapElement.Width, mapElement.Height);
}
else
{
IPoint c = new Point(_appState.Extent.Centre);
double dx;
double dy;
if (_preserveMode == PreserveMode.Scale)
{
double ratio = _appState.Extent.Width * 96 / _originalWidth;
dx = mapElement.Width * ratio * 0.5;
dy = mapElement.Height * ratio * 0.5;
}
else
{
dx = _appState.Extent.Width * 0.5;
dy = dx * mapElement.Height / mapElement.Width;
}
_appState.Extent = new Envelope(new Coordinate(c.Coordinate.X - dx, c.Coordinate.Y - dy), new Coordinate(c.Coordinate.X + dx, c.Coordinate.Y + dy));
}
double conversion = AppSettings.MapUnits == "feet" ? 1 : Constants.FeetPerMeter;
mapScale = _appState.Extent.Width * conversion / mapElement.Width;
_pixelSize = _appState.Extent.Width / (mapElement.Width * PixelsPerInch);
}
int inputIndex = 0;
// get the page template elements and draw each one to the page
foreach (Configuration.PrintTemplateContentRow element in printTemplate.GetPrintTemplateContentRows())
{
switch (element.ContentType)
{
case "box":
CreatePdfBox(content, element);
break;
case "date":
CreatePdfText(content, element, DateTime.Now.ToString("MMMM d, yyyy"));
break;
case "image":
CreatePdfImage(content, element);
break;
case "legend":
CreatePdfLegend(content, element);
break;
case "map":
CreatePdfMap(content, element);
break;
case "overviewmap":
CreatePdfOverviewMap(content, element);
break;
case "scale":
if (mapScale > 0)
{
CreatePdfText(content, element, "1\" = " + mapScale.ToString("0") + " ft");
}
//.........这里部分代码省略.........