差分
ナビゲーションに移動
検索に移動
header( "HTTP/1.1 301 Moved Permanently" );
header( "Location: http://monobook.org/wiki/PHP" );
</source>
[[ASP.NET MVC 2]]以前で301リダイレクトをしたい場合はActionResultクラスを継承した自前クラスを作る。
<source lang="csharp">
using System.Web.Mvc;
public class PermanentRedirectResult : ActionResult
{
public string Url { get; set; }
public PermanentRedirectResult(string url)
{
this.Url = url;
}
public override void ExecuteResult(ControllerContext context)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
if (string.IsNullOrEmpty(this.Url))
{
throw new ArgumentException("url is null or empty", "Url");
}
context.HttpContext.Response.StatusCode = 301;
context.HttpContext.Response.RedirectLocation = this.Url;
context.HttpContext.Response.End();
}
}
</source>