わかりました、これは実行できますが、HttpHandler
. ここで良い例を見つけることができますが、重要な部分を詳しく説明します。ここでハンドラー全体を適切に記述することはできません。
まず、Web プロジェクトでクラスを作成して呼び出しましょうImageHandler
...
public class ImageHandler : IHttpHandler
{
}
... 次にインターフェースを実装しましょう ...
public bool IsReusable
{
get { return false; }
}
public void ProcessRequest(HttpContext context)
{
// find out what we're trying to do first
string method = context.Request.HttpMethod;
switch (method)
{
case "GET":
// read the query string for the document name or ID
// read the file in from the shared folder
// write those bytes to the response, ensuring to set the Reponse.ContentType
// and also remember to issue Reponse.Clear()
break;
case "PUT":
// read the Headers from the Request to get the byte[] of the file to CREATE
// write those bytes to disk
// construct a 200 response
break;
case "POST":
// read the Headers from the Request to get the byte[] of the file to UPDATE
// write those bytes to disk
// construct a 200 response
break;
case "DELETE":
// read the Headers from the Request to get the byte[] of the file to DELETE
// write those bytes to disk
// construct a 200 response
break;
}
}
web.config
... 最後に、 ...でハンドラーをセットアップする必要があります。
<configuration>
<system.web>
<httpHandlers>
<!-- remember that you need to replace the {YourNamespace} with your fully qualified -->
<!-- namespace and you need to replace {YourAssemblyName} with your assembly name -->
<!-- EXCLUDING the .dll -->
<add verb="*" path="*/images/*" type="{YourNamespace}.ImageHandler, {YourAssemblyName}" />
</httpHandlers>
</system.web>
</configuration>
最後に、ハンドラーに入ったときに検証できるある種のセッション キーを渡すことも必要です。PUT
,動詞が必要ないかどうかは問題ではありませんが、必要POST
ですDELETE
GET
技術的には、誰もが にアクセスできることを気にしないのであれば、セッション キーをチェックする必要はありませんがGET
、他の人についてはチェックする必要があります。