差分
RedirectResultクラスとは、[[ASP.NET MVC]]の[[アクション・メソッド]]の戻り値([[ActionResultクラス]]およびその派生クラス)として、[[Webブラウザ]]に対して指定されたURIにリダイレクトするよう指示するHTTPレスポンスヘッダーを生成、送信するクラスである。
== 使い方 ==
RedirectResultクラスの使い方はいたって簡単。
単純にリダイレクト先のURLを指定するだけである。
これでWebブラウザに対して[[302リダイレクト]]を送信する。
<source lang="csharp">
using System.Web.Mvc;
public class HomeController : Controller {
public ActionResult Index() {
return new RedirectResult( "http://monobook.org/wiki/PHP" );
}
}
</source>
これは[[PHP]]でいう以下のコードに相当する。
<source lang="php">
<?php
header( "Location: http://monobook.org/wiki/PHP" );
</source>
=== 301リダイレクト ===
[[ASP.NET MVC 3]]では、bool型のPermanentプロパティが追加され、永続的に移転したことを示す永久リダイレクト([[301リダイレクト]])を発生させるかを指定できるようになった。
なお、[[ASP.NET MVC 3]]で追加されたものであり[[ASP.NET MVC 2]]以前では存在しないので注意。
<source lang="csharp">
using System.Web.Mvc;
public class HomeController : Controller {
public ActionResult Index() {
return new RedirectResult( "http://monobook.org/wiki/PHP", true );
}
}
</source>
これは[[PHP]]でいう以下のコードに相当する。
<source lang="php">
<?php
header( "HTTP/1.1 301 Moved Permanently" );
header( "Location: http://monobook.org/wiki/PHP" );
</source>
== 関連項目 ==
* [[ActionResult クラス (System.Web.Mvc)]] - アクションの戻り値
* [[ASP.NET MVC]]
== 参考文献 ==
<references />
== 外部リンク ==
{{stub}}
== 使い方 ==
RedirectResultクラスの使い方はいたって簡単。
単純にリダイレクト先のURLを指定するだけである。
これでWebブラウザに対して[[302リダイレクト]]を送信する。
<source lang="csharp">
using System.Web.Mvc;
public class HomeController : Controller {
public ActionResult Index() {
return new RedirectResult( "http://monobook.org/wiki/PHP" );
}
}
</source>
これは[[PHP]]でいう以下のコードに相当する。
<source lang="php">
<?php
header( "Location: http://monobook.org/wiki/PHP" );
</source>
=== 301リダイレクト ===
[[ASP.NET MVC 3]]では、bool型のPermanentプロパティが追加され、永続的に移転したことを示す永久リダイレクト([[301リダイレクト]])を発生させるかを指定できるようになった。
なお、[[ASP.NET MVC 3]]で追加されたものであり[[ASP.NET MVC 2]]以前では存在しないので注意。
<source lang="csharp">
using System.Web.Mvc;
public class HomeController : Controller {
public ActionResult Index() {
return new RedirectResult( "http://monobook.org/wiki/PHP", true );
}
}
</source>
これは[[PHP]]でいう以下のコードに相当する。
<source lang="php">
<?php
header( "HTTP/1.1 301 Moved Permanently" );
header( "Location: http://monobook.org/wiki/PHP" );
</source>
== 関連項目 ==
* [[ActionResult クラス (System.Web.Mvc)]] - アクションの戻り値
* [[ASP.NET MVC]]
== 参考文献 ==
<references />
== 外部リンク ==
{{stub}}