HttpContext.Current.Response.Status = "301 Moved Permanently";
HttpContext.Current.Response.AddHeader("Location", "(リダイレクト先URL)");
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Redirect301
{
public partial class _default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
HttpContext.Current.Response.Status = "301 Moved Permanently";
HttpContext.Current.Response.AddHeader("Location", "http://www.ipentec.com");
}
}
}
HttpContext.Current.Response.Status = "301 Moved Permanently";
にて、301のステータスコードを設定します。HttpContext.Current.Response.AddHeader("Location", "http://www.ipentec.com");
AddHederメソッドを呼び出して、Locationパラメータにリダイレクト先のURLを設定します。上記のコードではhttp://www.ipentec.com へのリダイレクトを設定しています。