Last active
January 12, 2018 11:32
-
-
Save kuju63/0cb2588f239995051364de25979c9106 to your computer and use it in GitHub Desktop.
ASP.NET MVCでのセッションへの格納・取得
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Web.Mvc; | |
namespace WebApplication1.Controllers | |
{ | |
/// <summary> | |
/// セッションに格納するデータ | |
/// </summary> | |
[Serializable] | |
public class Foo | |
{ | |
/// <summary> | |
/// セッションデータ | |
/// </summary> | |
public string Bar { get; set; } | |
} | |
public class SampleController : Controller | |
{ | |
// GET: Sample | |
public ActionResult Index() | |
{ | |
var sessionData = new Foo(); | |
sessionData.Bar = "bar"; | |
// セッションへの格納 | |
Session["SESSION_KEY"] = sessionData; | |
return View(); | |
} | |
public ActionResult Next() | |
{ | |
// セッションの取得 | |
var sessionData = Session["SESSION_KEY"] as Foo; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment