0

その場でサムネイルを作成するこのアクションメソッドがあります:

    public ActionResult Thumbnail(int imageId, int width, int height)
    {
        Image image = ImageManager.GetImage(imageId);
        string thumbnailPath;
        if (image.HasThumbnail(width, height))
        {
            thumbnailPath = image.GetThumbnailPath(width, height);
        }
        else
        {
            thumbnailPath = image.CreateThumbnail(width, height);
        }
        /*
        Here, I've done the business of thumbnail creation,
        now since it's only a static resource, I want to let IIS serve it.
        What should I do? Using HttpContext.RewritePaht() doesn't work, as 
        I have to return an ActionResult here.
        */
        return File(image.GetThumbnailPath(width, height), image.MimeType);
    }

このメソッドを呼び出す URL の例は次のとおりです。

/create-thumbnail/300x200/for-image/34

しかし、この方法でサムネイル作成業務を行った後は、IIS にサムネイルを提供させたいと考えています。私は何をすべきか?コントロールを IIS に戻すにはどうすればよいですか?

4

1 に答える 1

1

サムネイルがファイル システム上に作成されている場合は、次のいずれかのアクション結果タイプを使用して返すことができます。

FileContentResult
FilePathResult
FileStreamResult

..編集..出力キャッシュに関するより関連性の高い回答で私の応答を更新します。

おそらく、Asp.net のOuput Cachingの記事を参照してください。

基本的に、MVC でアクションが呼び出されるたびに、関数全体が再度実行されることが前提となります。これは、サムネイルのような単純なものの場合、パフォーマンスに大きな影響を与える可能性があります。代わりに、アクションを OutputCache でデコレートすると、キャッシュ タイマーを設定してパフォーマンスを向上させることができます。

[OutputCache(Duration = int.MaxValue, VaryByParam = "id;param1;param2")]

VaryByParam のドキュメント

于 2012-06-03T15:52:19.123 に答える