本文整理汇总了C#中System.Web.HttpResponseBase.TransmitFile方法的典型用法代码示例。如果您正苦于以下问题:C# HttpResponseBase.TransmitFile方法的具体用法?C# HttpResponseBase.TransmitFile怎么用?C# HttpResponseBase.TransmitFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.HttpResponseBase
的用法示例。
在下文中一共展示了HttpResponseBase.TransmitFile方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteEntireEntity
protected override void WriteEntireEntity(HttpResponseBase response)
{
try
{
response.TransmitFile(FileName);
}
// ReSharper disable EmptyGeneralCatchClause
catch
// ReSharper restore EmptyGeneralCatchClause
{
}
}
示例2: WriteEntityRange
protected override void WriteEntityRange(HttpResponseBase response, long rangeStartIndex, long rangeEndIndex)
{
int length = Convert.ToInt32(rangeEndIndex - rangeStartIndex) + 1;
try
{
response.TransmitFile(FileName, rangeStartIndex, length);
}
// ReSharper disable EmptyGeneralCatchClause
catch
// ReSharper restore EmptyGeneralCatchClause
{
}
}
示例3: SendContent
public virtual bool SendContent(string url, HttpResponseBase response)
{
var file = GetFileNameFromConfig(url);
try
{
response.TransmitFile(file);
RRTracer.Trace("{0} transmitted from disk.", url);
return true;
}
catch (FileNotFoundException)
{
try
{
response.TransmitFile(file.Insert(file.LastIndexOf('-'), "-Expired"));
RRTracer.Trace("{0} was expired and transmitted from disk.", url);
return true;
}
catch (FileNotFoundException)
{
return false;
}
}
}
示例4: Serve
public void Serve(HttpResponseBase response, long offset, long length)
{
response.TransmitFile(FileName, offset, length);
}
示例5: TryTransmitIfContains
private bool TryTransmitIfContains(string id, HttpResponseBase response) {
if (EnableAutoPurge) {
QueueAutoPurge();
}
string path = BuildFilePath(id);
lock (GetFileLockObject(id)) {
if (File.Exists(path)) {
response.TransmitFile(path);
return true;
}
else {
return false;
}
}
}
示例6: TransmitFile
/// <summary>
/// Writes file to response, adds correct headers based on Request headers and file attributes
/// </summary>
/// <param name="response"></param>
protected virtual void TransmitFile(HttpResponseBase response)
{
var contentLength = ContentLength();
response.StatusCode = SendRange() ? (int)HttpStatusCode.PartialContent : (int)HttpStatusCode.OK;
response.AppendHeader(HttpHeaders.ContentLength, contentLength.ToString(CultureInfo.InvariantCulture));
response.AppendHeader(HttpHeaders.AcceptRanges, "bytes");
response.AppendHeader(HttpHeaders.ContentRange, string.Format("bytes {0}-{1}/{2}", _range.Start, _range.End, _file.Length));
if(!string.IsNullOrWhiteSpace(_downloadFileName))
{
response.AddHeader("Content-Disposition", string.Format("attachment;filename=\"{0}\"", _downloadFileName));
}
try
{
response.TransmitFile(FileName, _range.Start, contentLength);
}
catch (Exception ex)
{
if(LogException != null)
{
LogException(ex);
}
}
}
示例7: WriteFile
protected override void WriteFile(HttpResponseBase response) {
response.TransmitFile(FileName);
}
示例8: TryTransmitIfContains
private bool TryTransmitIfContains (string id, HttpResponseBase response, string imgFile)
{
var tmpFiles = Directory.GetFiles (CachePath, id + "_*" + tmpFileExtension);
// check if we have cache files
if (tmpFiles.Length > 0)
{
// TODO: Log warning about duplicate cache entries
// we expect to find just one file for each ID
var tmpFile = tmpFiles [0];
lock (GetFileLockObject(tmpFile))
{
// get tmp short filename without extension
var tmpFileName = Path.GetFileNameWithoutExtension (Path.GetFileName (tmpFile));
// extract expire time
var expireTime = DateTime.MinValue;
var timeIndex = tmpFileName.LastIndexOf ("_") + 1;
if (timeIndex > 0)
expireTime = DateTime.FromFileTime (
Convert.ToInt64(tmpFileName.Substring (timeIndex)));
var hitCache = false;
if (imgFile == "")
{
// check if cache is expired
hitCache = expireTime >= DateTime.Now;
}
else if (timeIndex == 0)
{
// use original file last write time
var imgFileInfo = new FileInfo (imgFile);
var tmpFileInfo = new FileInfo (tmpFile);
hitCache = tmpFileInfo.LastWriteTime > imgFileInfo.LastWriteTime;
}
if (hitCache)
{
response.TransmitFile (tmpFile);
return true;
}
else
{
File.Delete (tmpFile);
return false;
}
}
}
return false;
}