如何防止母版页标题被缓存? [英] How to prevent master page header getting cached?

查看:93
本文介绍了如何防止母版页标题被缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我的要求是从我的项目文件夹下载文件..我写了以下代码:







<前lang =c#> 受保护 void btnOpenSampleExcel_Click( object sender,EventArgs e)
{
尝试
{
string fileName = SampleRetsServerCredentials.csv;
string filePath = Server.MapPath( /SampleRetsCredential\\SampleRetsServerCredentials.csv);
Response.AppendHeader( content-disposition filename = + fileName);
Response.ContentType = application / octet-stream;
Response.WriteFile(filePath, false );
}

catch (例外情况)
{
_alertMessage = 抱歉,现在无法显示示例文件!请稍后再试。;
radManager.RadAlert( message 400 null title null );
}
}











下载工作正常,但主页面标题部分也在下载后显示在csv中。我怎样才能防止这种行为。



谢谢,

Amrutha。

解决方案





在写入文件流之前,请先清除您的回复。



例如



   Response.Clear();   
Response.AppendHeader( content-disposition filename = + fileName );
Response.ContentType = application / octet-stream;
Response.WriteFile(filePath, false );


Hi,

My requirement was to download a file from my project folder.. i wrote the following code:



protected void btnOpenSampleExcel_Click(object sender, EventArgs e)
{
    try
    {
        string fileName = "SampleRetsServerCredentials.csv";
        string filePath = Server.MapPath("/SampleRetsCredential\\SampleRetsServerCredentials.csv");
        Response.AppendHeader("content-disposition", "filename=" + fileName);
        Response.ContentType = "application/octet-stream";
        Response.WriteFile(filePath, false);
    }

    catch (Exception ex)
    {
        _alertMessage = "Sorry, cant show the sample file now! Please try after some time.";
        radManager.RadAlert("message", 400, null, "title", null);
    }
}






Download is working correctly, but the Master page header portion is also shown in the csv after downloading.. How can i prevent such a behaviour.

Thanks,
Amrutha.

解决方案

Hi,

Just clear your response before write the file stream.

e.g.

Response.Clear();
Response.AppendHeader("content-disposition", "filename=" + fileName);
Response.ContentType = "application/octet-stream";
Response.WriteFile(filePath, false);


这篇关于如何防止母版页标题被缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆