小编jac*_*ick的帖子

在.NET Core中等效的HttpContext.Response.Cache?

我正在尝试重现我在这里找到的以前版本的ASP.NET的东西.

基本上,我希望能够禁用缓存,以便我的客户端始终向服务器查找信息.我为此添加了一个HTML元标记,但是对于已经拥有此信息的客户端,我想尝试在后端处理缓存策略.

帖子提到这样做是为了将缓存策略设置为动作过滤器.

public class NoCacheAttribute : ActionFilterAttribute
{  
public override void OnResultExecuting(ResultExecutingContext filterContext)
{
    filterContext.HttpContext.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
    filterContext.HttpContext.Response.Cache.SetValidUntilExpires(false);
    filterContext.HttpContext.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
    filterContext.HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);
    filterContext.HttpContext.Response.Cache.SetNoStore();

    base.OnResultExecuting(filterContext);
}
}
Run Code Online (Sandbox Code Playgroud)

但是,HttpContext似乎在ASP.NET Core中没有Response.Cache.有没有其他方法可以做到这一点?

谢谢!

.net asp.net asp.net-mvc .net-core asp.net-core

4
推荐指数
1
解决办法
2558
查看次数

通过我的 Azure Web 应用上传文件时超时

通过作为 Azure Web 应用托管的 .NET Core 应用程序上传文件时,我收到以下错误:

您要查找的资源已被删除、更名或暂时不可用。

这在 Postman 中进行了测试,并在大约 22 秒时出现 404 Not Found 超时。

我的应用程序代码如下,去掉多余的东西:

    public async Task<IActionResult> PostDocuments(ICollection<IFormFile> files)
    {
        foreach (var file in files)
        {
                string path = Path.Combine(uploadsDir, file.FileName);

                //Uploading file to "uploads" to be staged. Doesn't get past here.
                using (var stream = new FileStream(Path.Combine(uploadsDir, file.FileName), FileMode.Create))
                {
                    await file.CopyToAsync(stream);
                }

                //Uploading files to Azure
                if (await _azure.UploadFile(path, file.FileName)
                {
                    // Stuff to add file to database
                }
                else
                {
                    return StatusCode(400, "Could …
Run Code Online (Sandbox Code Playgroud)

.net azure asp.net-core

3
推荐指数
1
解决办法
1147
查看次数

标签 统计

.net ×2

asp.net-core ×2

.net-core ×1

asp.net ×1

asp.net-mvc ×1

azure ×1