IISのようなデフォルトのアプリケーションサーバーに設定するだけです。ashxへのハンドラーを作成することがポイントである場合は、次のように実行できます。
したがって、rss.ashxを作成することから始めます
<!--WebHandler Language="C#" Class="KBMentor2.RSSHandler"-->
次に、ハンドラークラスを見てみましょう。
RSSHandler.cs
namespace KBMentor2
{
using System;
using System.IO;
using System.Web;
public class RSSHandler : IHttpHandler
{
public void ProcessRequest (HttpContext context)
{
context.Response.ContentType = "text/xml";
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
string sXml = BuildXMLString(); //not showing this function,
//but it creates the XML string
context.Response.Cache.SetExpires(DateTime.Now.AddSeconds(600));
context.Response.Cache.SetCacheability(HttpCacheability.Public);
context.Response.Write( sXml );
}
public bool IsReusable
{
get { return true; }
}
}
}
そして、あなたはそれを持っています。私たちが作成した最初のコードとほとんど同じように見えますね。キャッシュについては、コードからCacheオブジェクトにアクセスすることで解決できます。context.Response.Cache呼び出しを参照してください。
コードのソースは次のとおりです:aspcode.net