0

静的なWebサイト(「Plone」で作成)をASP.NETプロジェクトに変換していますが、画像を参照する方法がおかしく、ASP.NETでは機能しません。

構造は次のように/images/image.png/image_thumbなります。/images/image.png/image_tile

image.pngはフォルダでimage_thumbありimage_tile、ファイルです。各ファイルに手動で拡張子を追加してそれを参照する以外に何をする必要がありますか?

画像が現在どのように参照されているかを次に示します(古い静的プロジェクトでは機能しますが、ASP.NETでは機能しません)。<img alt="Shallow Tiger" class="image-inline" height="300" src="/images/rm/ue147.JPG/image_preview" width="400" />

Global.asaxで行う必要がありますか?またはweb.config?またはIIS?

4

2 に答える 2

0

IISはファイルの種類を知る方法を必要とし、それを行うためにイメージの拡張子を使用しているため、設計が不適切です。拡張機能がない場合は、コードを追加して、次global.asaxのようにディレクトリでフィルタリングすることもできます。

protected void Application_BeginRequest(Object sender, EventArgs e)
{
    HttpApplication app = (HttpApplication)sender;
    string cTheFile = HttpContext.Current.Request.Path;
    string sExtentionOfThisFile = System.IO.Path.GetExtension(cTheFile);

    // if this is a file inside the directory images
    // and did not have extention
    if (   cTheFile.Contains("/images/", StringComparison.InvariantCultureIgnoreCase)
        && sExtentionOfThisFile.Equals(".", StringComparison.InvariantCultureIgnoreCase)
    )
    {
        // then send the Content type of a jpeg (if its jpeg)
        app.Response.ContentType = "image/jpeg";
    }

}

ただし、これで画像の拡張子を簡単に返すことができ、IISにContentTypeと画像のキャッシュセットを処理させることをお勧めします。

私はそれをそのままテストしていないので、コードは数週間かかるかもしれません。 また、これを機能させるには、拡張子のないファイルをasp.netから続行するようにiisを設定する必要があります。

于 2012-12-13T07:58:40.130 に答える
0

If you can't automate your way out of this situation, then I would suggest writing an HTTP handler that reads an image from disk, writes the bytes to the response and adds the proper mime type to the response.

You can configure a handler in web.config, here's an example:

<system.web>
  <httpHandlers>
     <add verb="GET" path="images/*" type="ExtensionLesssImageHandler, WebApplication1" />
  </httpHandlers>

于 2012-12-13T08:03:55.510 に答える