首页 新闻 会员 周边

ASP.NET Core: 如何在 StaticFileOptions 的 OnPrepareResponse 中清除 response body

0
悬赏园豆:30 [已解决问题] 解决于 2023-08-17 07:37

通过 Response.Clear() 清除不掉,响应内容中依然包含静态文件的内容,请问如何解决?

var options = new StaticFileOptions
{
    OnPrepareResponse = ctx =>
    {
        ctx.Context.Response.Clear();
    }
};
dudu的主页 dudu | 高人七级 | 园豆:30948
提问于:2023-08-17 07:24
< >
分享
最佳答案
0

How can I protect static files with authorization on ASP.NET Core? 中找到了解决方法

var options = new StaticFileOptions
{
    OnPrepareResponse = ctx =>
    {
        ctx.Context.Response.ContentLength = 0;
        ctx.Context.Response.Body = Stream.Null;
    }
};
dudu | 高人七级 |园豆:30948 | 2023-08-17 07:37
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册