创建到期链接到S3或者的Cloudfront托管内容的ASP.NET [英] Creating expiring links to S3 or Cloudfront hosted content with ASP .Net

查看:143
本文介绍了创建到期链接到S3或者的Cloudfront托管内容的ASP.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都有创造一个标识的URL使用ASP .NET中过期的例子吗?我使用的是探索 LitS3 或的 ThreeSharp 在我的项目,并没有看到任何具体的方法来做到这一点在任何这些项目。谢谢你。

Anyone have an example of creating a signed URL with an expiration using ASP .Net? I'm exploring using LitS3 or ThreeSharp in my project, and have not seen any specific methods to do this in either of those projects. Thanks.

推荐答案

下面的(基于以上问题的答案,我发现上的 http://www.ec2studio.com/articles/s3.html ):

Here's what worked for me with the AWS SDK and MVC 3 (based on the answers above and what I found on http://www.ec2studio.com/articles/s3.html):

public ActionResult GetS3Object(string bucket, string key)
{
    string accessKeyID = ConfigurationManager.AppSettings["AWSAccessKey"];
    string secretAccessKeyID = ConfigurationManager.AppSettings["AWSSecretKey"];
    using (AmazonS3 client = Amazon.AWSClientFactory.CreateAmazonS3Client(accessKeyID, secretAccessKeyID))
        {
        GetPreSignedUrlRequest request = new GetPreSignedUrlRequest()
            .WithBucketName(bucket)
            .WithKey(key)
            .WithExpires(DateTime.Now.Add(new TimeSpan(7, 0, 0, 0)));
        return Redirect(client.GetPreSignedURL(request));
        }
}

这篇关于创建到期链接到S3或者的Cloudfront托管内容的ASP.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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