本文整理汇总了C#中System.Web.HttpResponse.ClearHeaders方法的典型用法代码示例。如果您正苦于以下问题:C# HttpResponse.ClearHeaders方法的具体用法?C# HttpResponse.ClearHeaders怎么用?C# HttpResponse.ClearHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.HttpResponse
的用法示例。
在下文中一共展示了HttpResponse.ClearHeaders方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendFileNotFound
private static void SendFileNotFound(HttpResponse response)
{
response.ClearHeaders();
response.StatusCode = 404; //not found
response.StatusDescription = "Not Found";
response.End();
}
示例2: DataTableToExcel
/// <summary>
/// Datatable数据填充如excel
/// </summary>
/// <param name="filename">excel文件名</param>
/// <param name="dt"> 数据源</param>
/// <param name="Response"> response响应</param>
/// <param name="headerStr"> 表头标题</param>
public static void DataTableToExcel(string filename, DataTable dt, string sheetname, HttpResponse Response, string headerStr)
{
MemoryStream ms = StreamData(dt, sheetname, headerStr) as MemoryStream; //as MemoryStream as用作转换,此处可以省略
try
{
Response.Clear();
Response.ContentType = "application/vnd.ms-excel";
Response.ContentEncoding = Encoding.UTF8;
Response.AddHeader("content-disposition", "attachment;filename=" + HttpUtility.UrlEncode(filename + ".xls"));
Response.AddHeader("content-length", ms.Length.ToString());
Byte[] data = ms.ToArray(); //文件写入采用二进制流的方式。所以此处要转换为字节数组
Response.BinaryWrite(data);
}
catch
{
Response.Clear();
Response.ClearHeaders();
Response.Write("<script language=javascript>alert( '导出Excel错误'); </script>");
}
Response.Flush();
Response.Close();
Response.End();
ms = null;
}
示例3: WriteToHttpResponse
internal void WriteToHttpResponse(HttpResponse httpResponse)
{
httpResponse.ClearContent();
httpResponse.ClearHeaders();
httpResponse.ContentType = model.ContentType;
httpResponse.AddHeader("Content-Disposition", ContentDisposition);
WriteToStream(httpResponse.OutputStream);
}
示例4: SendNotModified
private static void SendNotModified(HttpResponse response)
{
response.ClearHeaders();
setCacheHeaders(response);
response.StatusCode = 304; // not modified
response.StatusDescription = "Not Modified";
response.End();
}
示例5: JsonResponse
public static void JsonResponse(HttpResponse response, Action<JsonWriter> writeAction)
{
response.ClearHeaders();
response.ClearContent();
JsonWriter writer = new JsonWriter(response.Output);
writeAction(writer);
writer.Flush();
}
示例6: SendToResponse
/// <summary>
/// Sends the file to the response with content-length header
/// Works with all types of files, not image specific
/// </summary>
/// <param name="response"></param>
/// <param name="file"></param>
/// <param name="mimetype"></param>
private static void SendToResponse(HttpResponse response, byte[] fileContent, DateTime lastWriteTime, string mimetype)
{
response.ClearHeaders();
setCacheHeaders(response);
response.Cache.SetLastModified(lastWriteTime); // to avoid rounding problems with header (no millisecs there)
response.ContentType = mimetype;
response.AppendHeader("Content-Length", fileContent.Length.ToString());
response.BinaryWrite(fileContent);
response.End();
}
示例7: XmlResponse
public static void XmlResponse(HttpResponse response, Action<XmlTextWriter> writeAction)
{
response.ClearHeaders();
response.ClearContent();
response.ContentType = "text/xml";
XmlTextWriter writer = new XmlTextWriter(response.Output);
writeAction(writer);
writer.Flush();
}
示例8: Run
public static void Run()
{
// ExStart:SendingPdfToBrowser
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdfGenerator_AdvanceFeatures();
// Instantiate Pdf instance by calling its empty constructor
Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();
MemoryStream stream = new MemoryStream();
HttpResponse Response = new HttpResponse(null);
pdf1.Save(stream);
Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.Charset = "UTF-8";
Response.AddHeader("Content-Length", stream.Length.ToString());
Response.AddHeader("content-disposition", String.Format("attachment;filename={0}", dataDir + "SendingPdfToBrowser.pdf"));
Response.ContentType = "application/pdf";
Response.BinaryWrite(stream.ToArray());
Response.Flush();
Response.End();
// ExEnd:SendingPdfToBrowser
}
示例9: SetNoCacheNoStore
/// <summary>
/// Sets No Chache to Cliente browser
/// </summary>
/// <param name="response"></param>
public static void SetNoCacheNoStore(HttpResponse response)
{
response.ClearHeaders();
response.AppendHeader("Cache-Control", "no-cache"); //HTTP 1.1
response.AppendHeader("Cache-Control", "private"); // HTTP 1.1
response.AppendHeader("Cache-Control", "no-store"); // HTTP 1.1
response.AppendHeader("Cache-Control", "must-revalidate"); // HTTP 1.1
response.AppendHeader("Cache-Control", "max-stale=0"); // HTTP 1.1
response.AppendHeader("Cache-Control", "post-check=0"); // HTTP 1.1
response.AppendHeader("Cache-Control", "pre-check=0"); // HTTP 1.1
response.AppendHeader("Pragma", "no-cache"); // HTTP 1.1
response.AppendHeader("Keep-Alive", "timeout=3, max=993"); // HTTP 1.1
response.AppendHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT"); // HTTP 1.1
response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
response.Cache.SetCacheability(HttpCacheability.Private);
response.Cache.SetNoStore();
}
示例10: SendResponse
public override void SendResponse( HttpResponse response )
{
// Cleans the response buffer.
response.ClearHeaders();
response.Clear();
// Prevent the browser from caching the result.
response.CacheControl = "no-cache";
// Set the response format.
response.ContentEncoding = System.Text.UTF8Encoding.UTF8;
response.ContentType = "text/xml";
_Xml = new XmlDocument();
// Create the XML document header.
_Xml.AppendChild( _Xml.CreateXmlDeclaration( "1.0", "utf-8", null ) ) ;
// Create the main "Connector" node.
_ConnectorNode = XmlUtil.AppendElement( _Xml, "Connector" ) ;
XmlNode oErrorNode = XmlUtil.AppendElement( this.ConnectorNode, "Error" ) ;
try
{
this.CheckConnector();
if ( this.MustCheckRequest() )
this.CheckRequest();
if ( this.CurrentFolder.ResourceTypeName.Length > 0 )
XmlUtil.SetAttribute( _ConnectorNode, "resourceType", this.CurrentFolder.ResourceTypeName );
if ( this.MustIncludeCurrentFolder() )
{
// Add the current folder node.
XmlNode currentFolder = XmlUtil.AppendElement( _ConnectorNode, "CurrentFolder" );
XmlUtil.SetAttribute( currentFolder, "path", this.CurrentFolder.ClientPath );
try
{
XmlUtil.SetAttribute( currentFolder, "url", this.CurrentFolder.Url );
}
catch
{
XmlUtil.SetAttribute( currentFolder, "url", "" );
}
XmlUtil.SetAttribute( currentFolder, "acl", this.CurrentFolder.AclMask.ToString() );
}
this.BuildXml();
XmlUtil.SetAttribute( oErrorNode, "number", "0" );
}
catch ( ConnectorException connectorException )
{
XmlUtil.SetAttribute( oErrorNode, "number", connectorException.Number.ToString() );
}
catch
{
#if DEBUG
throw;
#else
XmlUtil.SetAttribute( oErrorNode, "number", Errors.Unknown.ToString() );
#endif
}
// Output the resulting XML.
response.Write( _Xml.OuterXml ) ;
response.End() ;
}
示例11: VerifyHttpCompressionByMimeType
/// <summary>
/// Disables http compression for non-text contents
/// </summary>
/// <reason>BUGFIX v5.5b2: HttpCompression increases images size</reason>
private void VerifyHttpCompressionByMimeType(HttpResponse httpResponse, MimeContentType responseMimeType)
{
switch (responseMimeType)
{
case MimeContentType.text_html:
case MimeContentType.text_plain:
case MimeContentType.text_css:
case MimeContentType.text_javascript:
// nothing
// the compression remains if it is there
break;
case MimeContentType.image_jpeg:
case MimeContentType.image_gif:
case MimeContentType.application:
default:
// Disabling HttpCompression for this request
//httpResponse.Headers.Remove("Content-Encoding");
httpResponse.ClearHeaders();
if (httpResponse.Filter is GZipStream)
{
using (GZipStream compress = (GZipStream)httpResponse.Filter)
{
// reassign the original filter
httpResponse.Filter = compress.BaseStream;
}
}
else if (httpResponse.Filter is DeflateStream)
{
using (DeflateStream compress = (DeflateStream)httpResponse.Filter)
{
// reassign the original filter
httpResponse.Filter = compress.BaseStream;
}
}
break;
}
}
示例12: ClearHeadersButSaveEncoding
/// <summary>
/// Clears response header whitout harming http-compression header
/// </summary>
public static void ClearHeadersButSaveEncoding(HttpResponse response)
{
HttpCookie cookie = response.Cookies[Consts.FrontEndPresentation.HttpCompressor];
string encode = cookie[Consts.FrontEndPresentation.HttpCompressEncoding];
response.ClearHeaders();
if (string.IsNullOrEmpty(encode))
return;
response.AppendHeader("Content-Encoding", encode);
}
示例13: ReturnMessage
private void ReturnMessage(byte message, HttpResponse response)
{
response.StatusCode = 200;
response.ClearHeaders();
response.AppendHeader("Connection", "Keep-Alive");
response.AppendHeader("Content-Length", "1");
response.Cache.SetCacheability(HttpCacheability.NoCache);
response.ContentType = ContentType.RTMPT;
response.Write((char)message);
response.Flush();
}
示例14: Methods_Deny_Unrestricted
public void Methods_Deny_Unrestricted ()
{
HttpResponse response = new HttpResponse (writer);
response.AddCacheItemDependencies (new ArrayList ());
response.AddCacheItemDependency (String.Empty);
response.AddFileDependencies (new ArrayList ());
response.AddFileDependency (fname);
response.AddCacheDependency (new CacheDependency[0]);
response.AddCacheItemDependencies (new string [0]);
response.AddFileDependencies (new string [0]);
try {
response.AppendCookie (new HttpCookie ("mono"));
}
catch (NullReferenceException) {
// ms
}
try {
Assert.IsNull (response.ApplyAppPathModifier (null), "ApplyAppPathModifier");
}
catch (NullReferenceException) {
// ms
}
try {
response.Clear ();
}
catch (NullReferenceException) {
// ms
}
try {
response.ClearContent ();
}
catch (NullReferenceException) {
// ms
}
try {
response.ClearHeaders ();
}
catch (NullReferenceException) {
// ms
}
try {
response.Redirect ("http://www.mono-project.com");
}
catch (NullReferenceException) {
// ms
}
try {
response.Redirect ("http://www.mono-project.com", false);
}
catch (NullReferenceException) {
// ms
}
try {
response.SetCookie (new HttpCookie ("mono"));
}
catch (NullReferenceException) {
// ms
}
response.Write (String.Empty);
response.Write (Char.MinValue);
response.Write (new char[0], 0, 0);
response.Write (this);
response.WriteSubstitution (new HttpResponseSubstitutionCallback (Callback));
response.Flush ();
response.Close ();
try {
response.End ();
}
catch (NullReferenceException) {
// ms
}
}
示例15: SetupResponse
private static void SetupResponse( HttpResponse response )
{
// Cleans the response buffer.
response.ClearHeaders();
response.Clear();
// Prevent the browser from caching the result.
response.CacheControl = "no-cache";
// Set the response format.
response.ContentEncoding = System.Text.UTF8Encoding.UTF8;
response.ContentType = "text/xml";
}