本文整理汇总了C#中System.Web.HttpResponse.ClearContent方法的典型用法代码示例。如果您正苦于以下问题:C# HttpResponse.ClearContent方法的具体用法?C# HttpResponse.ClearContent怎么用?C# HttpResponse.ClearContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.HttpResponse
的用法示例。
在下文中一共展示了HttpResponse.ClearContent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetImageFromFile
//defaultfile is under userpath
public static void GetImageFromFile(string filename,string defaultfile,HttpResponse response)
{
if (!File.Exists(filename))
{
string userdatapath = Functions.GetAppConfigString("UserDataPath", "");
filename = userdatapath + "\\"+defaultfile;
}
System.IO.FileStream fs = null;
System.IO.MemoryStream ms = null;
try
{
fs = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
fs.Close();
ms = new System.IO.MemoryStream(buffer);
response.ClearContent();
response.BinaryWrite(ms.ToArray());
ms.Close();
}
finally
{
fs.Dispose();
ms.Dispose();
}
}
示例2: WriteToHttpResponse
internal void WriteToHttpResponse(HttpResponse httpResponse)
{
httpResponse.ClearContent();
httpResponse.ClearHeaders();
httpResponse.ContentType = model.ContentType;
httpResponse.AddHeader("Content-Disposition", ContentDisposition);
WriteToStream(httpResponse.OutputStream);
}
示例3: ShowDownloadToolFile
public static bool ShowDownloadToolFile(HttpResponse httpResponse, NameValueCollection queryString, CommonUtils.AppSettingKey settingKey, out Exception message)
{
try
{
string fileName = queryString["DownloadToolFile"];
if (string.IsNullOrEmpty(fileName))
{
message = new Exception("Query string 'DownloadToolFile' missing from url.");
return false;
}
if (!File.Exists(fileName))
{
message = new FileNotFoundException(string.Format(@"Failed to find file '{0}'.
Please ask your administrator to check whether the folder exists.", fileName));
return false;
}
httpResponse.Clear();
httpResponse.ClearContent();
//Response.OutputStream.f
httpResponse.BufferOutput = true;
httpResponse.ContentType = "application/unknown";
httpResponse.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"", Path.GetFileName(fileName)));
byte[] fileContent = File.ReadAllBytes(fileName);
BinaryWriter binaryWriter = new BinaryWriter(httpResponse.OutputStream);
binaryWriter.Write(fileContent, 0, fileContent.Length);
binaryWriter.Flush();
binaryWriter.Close();
var dirName = Path.GetDirectoryName(fileName);
if (dirName != null)
{
//Delete any files that are older than 1 hour
Directory.GetFiles(dirName)
.Select(f => new FileInfo(f))
.Where(f => f.CreationTime < DateTime.Now.AddHours(-1))
.ToList()
.ForEach(f => f.Delete());
}
}
catch (Exception ex)
{
message = ex;
return false;
}
message = null;
return true;
}
示例4: JsonResponse
public static void JsonResponse(HttpResponse response, Action<JsonWriter> writeAction)
{
response.ClearHeaders();
response.ClearContent();
JsonWriter writer = new JsonWriter(response.Output);
writeAction(writer);
writer.Flush();
}
示例5: 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();
}
示例6: PrepareContent
protected void PrepareContent(ref HttpResponse response)
{
List<HttpCookie> list = new List<HttpCookie>(response.Cookies.Count);
for (int i = 0; i < response.Cookies.Count; i++)
{
list.Add(response.Cookies[i]);
}
//response.ClearHeaders();
response.ClearContent();
response.ContentType = "text/html";
for (int j = 0; j < list.Count; j++)
{
response.AppendCookie(list[j]);
}
response.Cache.SetCacheability(HttpCacheability.NoCache);
}
示例7: WriteResponse
public static void WriteResponse(HttpResponse response, byte[] filearray, string type)
{
response.ClearContent();
response.Buffer = true;
response.Cache.SetCacheability(HttpCacheability.Private);
response.ContentType = "application/pdf";
ContentDisposition contentDisposition = new ContentDisposition();
contentDisposition.FileName = "SaldoDotacao.pdf";
contentDisposition.DispositionType = type;
response.AddHeader("Content-Disposition", contentDisposition.ToString());
response.BinaryWrite(filearray);
HttpContext.Current.ApplicationInstance.CompleteRequest();
try
{
response.End();
}
catch (System.Threading.ThreadAbortException)
{
}
}
示例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: HandlePublicBlobRequestWithCacheSupport
private static void HandlePublicBlobRequestWithCacheSupport(HttpContext context, CloudBlob blob, HttpResponse response)
{
// Set the cache request properties as IIS will include them regardless for now
// even when we wouldn't want them on 304 response...
response.Cache.SetMaxAge(TimeSpan.FromMinutes(0));
response.Cache.SetCacheability(HttpCacheability.Private);
var request = context.Request;
blob.FetchAttributes();
string ifNoneMatch = request.Headers["If-None-Match"];
string ifModifiedSince = request.Headers["If-Modified-Since"];
if (ifNoneMatch != null)
{
if (ifNoneMatch == blob.Properties.ETag)
{
response.ClearContent();
response.StatusCode = 304;
return;
}
}
else if (ifModifiedSince != null)
{
DateTime ifModifiedSinceValue;
if (DateTime.TryParse(ifModifiedSince, out ifModifiedSinceValue))
{
ifModifiedSinceValue = ifModifiedSinceValue.ToUniversalTime();
if (blob.Properties.LastModifiedUtc <= ifModifiedSinceValue)
{
response.ClearContent();
response.StatusCode = 304;
return;
}
}
}
var fileName = blob.Name.Contains("/MediaContent/") ?
request.Path : blob.Name;
response.ContentType = StorageSupport.GetMimeType(fileName);
//response.Cache.SetETag(blob.Properties.ETag);
response.Headers.Add("ETag", blob.Properties.ETag);
response.Cache.SetLastModified(blob.Properties.LastModifiedUtc);
blob.DownloadToStream(response.OutputStream);
}
示例10: ShowFile
public static bool ShowFile(HttpResponse httpResponse, NameValueCollection queryString, CommonUtils.AppSettingKey settingKey, out Exception message)
{
try
{
string fileName = queryString["file"];
if (string.IsNullOrEmpty(fileName))
{
message = new Exception("Query string 'file' missing from url.");
return false;
}
string folderConfig = GetAppSettingValue(settingKey);
string folderPath = Path.Combine(folderConfig, fileName);
if (!Directory.Exists(folderPath))
{
message = new DirectoryNotFoundException(string.Format(@"Failed to find file '{0}' from this location: ({1}).
Please ask your administrator to check whether the folder exists.", fileName, folderPath));
return false;
}
var files = Directory.GetFiles(folderPath);
if (files.Any())
{
string filePath = files[0];
httpResponse.Clear();
httpResponse.ClearContent();
//Response.OutputStream.f
httpResponse.BufferOutput = true;
httpResponse.ContentType = "application/unknown";
httpResponse.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"", Path.GetFileName(filePath)));
byte[] fileContent = File.ReadAllBytes(filePath);
BinaryWriter binaryWriter = new BinaryWriter(httpResponse.OutputStream);
binaryWriter.Write(fileContent, 0, fileContent.Length);
binaryWriter.Flush();
binaryWriter.Close();
//httpResponse.Flush();
}
}
catch (Exception ex)
{
message = ex;
return false;
}
message = null;
return true;
}
示例11: HandleUserLookup
public static void HandleUserLookup(HttpRequest Request, HttpResponse Response, Guid userId)
{
try
{
ClientControlsReader r = new ClientControlsReader(Request.InputStream);
Response.ClearContent();
ClientControlsWriter w = new ClientControlsWriter(Response.OutputStream);
w.Write(1);
string query = Request["userquery"];
//Write result code
if(query == null || query.Length == 0)
{
w.Write(-1);
return;
}
else
w.Write(0);
query = "%"+query+"%";
ArrayList data = new ArrayList();
using(Db db = new Db())
{
db.CommandText = @"
SELECT id, fullNameClean as fullName, username, email
FROM tMember
WHERE fullName LIKE @q OR email LIKE @q OR username LIKE @q
ORDER BY fullNameClean ASC
";
db.AddParameter("@q", query);
while(db.Read())
{
UserInfo user = new UserInfo();
user.username = (string)db["username"];
user.id = (Guid)db["id"];
user.email = db["email"] as string;
user.name = (string)db["fullName"];
data.Add(user);
}
}
w.Write((int)data.Count);
foreach(object o in data)
{
if(o is UserInfo)
{
w.Write((byte)0);
UserInfo user = (UserInfo)o;
w.Write(user.id.ToByteArray());
w.WriteString(user.username);
w.WriteString(user.email);
w.WriteString(user.name);
}
}
int a = 3;
}
finally
{
Response.Flush();
Response.Close();
Response.End();
}
}
示例12: RenderAction
private void RenderAction(HttpResponse response, ActionResult result, bool isOther)
{
bool isSuccess = false;
string message = "系统运行出现未知严重错误";
string responseData = string.Empty;
if (result != null)
{
isSuccess = result.IsSuccess;
responseData = (result.ResponseData ?? string.Empty).Trim();
if (!isSuccess)
{
string mess = (result.TipMessage ?? string.Empty).Trim();
message = string.IsNullOrEmpty(mess) ? message : mess;
}
}
StringBuilder output = new StringBuilder();
output.Append(string.Format("{0} = {1};", (isOther) ? "Ssign" : "sign", (isSuccess) ? "true" : "false"));
output.Append(responseData);
if (!isSuccess)
{
if (!isOther)
output.Append(string.Format("BadInfo = '{0}<br>请重新操作!';", message));
}
response.ClearContent();
response.Write(Escape.JsEscape(output.ToString()));
response.End();
}
示例13: HandleCategoryLookup
static void HandleCategoryLookup(HttpRequest Request, HttpResponse Response, Guid userId)
{
try
{
Response.ClearContent();
ClientControlsWriter w = new ClientControlsWriter(Response.OutputStream);
//Version
w.Write((int)1);
//ResultCode
if(userId == Guid.Empty)
{
w.Write((int)-1);
return;
}
string categoryName = Request["categoryName"];
if(categoryName == null)
categoryName = string.Empty;
categoryName = categoryName.Trim();
if(!Validation.ValidateCategoryName(categoryName))
{
w.Write((int)-2);
return;
}
w.Write((int)0);
// } result code.
Database.MemberDetails details = Database.GetMemberDetails(null, userId);
Guid existingId = Database.GetSubCategory(userId, details.HomeCategoryId, categoryName);
Database.Category cat = null;
if(existingId != Guid.Empty)
cat = Database.GetCategoryInfo(userId, existingId);
w.Write(existingId != Guid.Empty);
w.Write(existingId.ToByteArray());
//canAddPermission
w.Write(cat != null && cat.CurrentPermission >= Permission.Add);
//securityPermission
w.Write(cat != null && cat.CurrentPermission >= Permission.Owner); //TODO: shold be securitypermission.
w.WriteString(cat != null?cat.Name:categoryName);
//can't send email
w.Write((byte)0x00);
//can't share to friends
w.Write((byte)0x00);
//Write the permission entries on the category.
if(existingId == Guid.Empty)
w.Write(0);
else
{
Guid groupId = Database.GetMemberGroup(userId, "$"+existingId);
Database.GroupMember[] members = Database.EnumGroupMembers(userId, groupId);
w.Write((uint)(members.Length-1)); //minus self
foreach(Database.GroupMember member in members)
{
if(member.MemberId == userId)
continue;
Database.MemberDetails md = Database.GetMemberDetails(null, member.MemberId);
w.Write((byte)0);
w.Write(md.Id.ToByteArray());
w.WriteString(md.admin_username);
w.WriteString(md.admin_email);
w.WriteString(md.Name);
w.Write((uint)0);
w.Write((uint)0);
w.Write((uint)0);
w.Write((uint)0);
}
}
}
finally
{
Response.Flush();
Response.Close();
Response.End();
}
}
示例14: ResponseImage2
/// <summary>
/// 产生验证图片信息
/// </summary>
/// <param name="checkCode"></param>
/// <param name="Response"></param>
protected void ResponseImage2(string checkCode, HttpResponse Response)
{
int iwidth = 80;// (int)(checkCode.Length * 25);
using (System.Drawing.Bitmap image = new System.Drawing.Bitmap(iwidth, 30))
{
System.Random rand = new Random(~unchecked((int)DateTime.Now.Ticks));
using (Graphics g = Graphics.FromImage(image))
{
g.Clear(Color.White);
//定义颜色
Color[] c = { Color.Black, Color.Red, Color.DarkBlue, Color.Green, Color.Orange, Color.Brown, Color.DarkCyan, Color.Purple, Color.SkyBlue };
//定义字体
string[] font = { "Verdana", "Microsoft Sans Serif", "Comic Sans MS", "Arial", "宋体", "Comic Sans MS" };
Color nowColor = c[rand.Next(8)]; //Color.FromArgb(rand.Next());
/*
//rand = new Random(~unchecked((int)DateTime.Now.Ticks));
//随机输出噪点
for (int i = 0; i < 50; i++)
{
int x = rand.Next(image.Width);
int y = rand.Next(image.Height);
//image.SetPixel(x, y, nowColor);
g.DrawPie(new Pen(nowColor, 0), x, y, 2, 2, 1, 1);
}
*/
//rand = new Random(~unchecked((int)DateTime.Now.Ticks));
//输出不同字体和颜色的验证码字符
for (int i = 0; i < checkCode.Length; i++)
{
int findex = rand.Next(6);
Font _font = new System.Drawing.Font(font[findex], 16, System.Drawing.FontStyle.Bold);
Brush b = new System.Drawing.SolidBrush(nowColor);
g.DrawString(checkCode.Substring(i, 1), _font, b, rand.Next(1, 8) + (i * 14), rand.Next(6));
}
/*
//rand = new Random(~unchecked((int)DateTime.Now.Ticks));
//画图片的前景噪音点
for (int i = 0; i < 50; i++)
{
int x = rand.Next(image.Width);
int y = rand.Next(image.Height);
//image.SetPixel(x, y, Color.FromArgb(rand.Next()));
//image.SetPixel(x, y, nowColor);
g.DrawPie(new Pen(nowColor, 0), x, y, 2, 2, 1, 1);
}
*/
//画一个边框
//g.DrawRectangle(new Pen(nowColor, 0), 0, 0, image.Width - 1, image.Height - 1);
}
rand = new Random(~unchecked((int)DateTime.Now.Ticks));
//using (var ximage = TwistImage(image, true, rand.Next(3, 8), rand.Next(1, 4)))
//{
System.IO.MemoryStream ms = new System.IO.MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
Response.ClearContent();
Response.ContentType = "image/png";
Response.BinaryWrite(ms.ToArray());
//}
}
}
示例15: WriteError
private static void WriteError(HttpResponse response)
{
response.StatusCode = (int)HttpStatusCode.NotFound;
response.ClearContent();
}