piano imagemap test

piano H-1 C0 CIS0 > D0 DIS0 E0 F0 FIS0 G0 GIS0 A0 B0 H0 C1 CIS1 D1 DIS1 E1 F1 FIS1 G1 GIS1 A1 B1 H1 C2 CIS2 D2 DIS2 E2 F2

Labels

Wirtschaft (156) Pressefreiheit (151) Österreich (125) IT (110) code (70) Staatsschulden (37) EZB (27) Pensionssystem (16) Geopolitik (12)

2013-05-17

ASP.NET C# - Stateful session by cookie

Online Sample: http://area23.at/default/Stateful.aspx
Attention, Request Timeouts and ApplicationError Events are not handled in this litte sample!

Code:

<form id="form1" runat="server"> 
    <asp:Literal ID="Literal1" runat="server"></asp:Literal>
    <br />
    CookieValue: <asp:TextBox ID="TextBox1" runat="server" MaxLength="4" Text="0"></asp:TextBox>
    <br />
    SessionValue: <asp:TextBox
ID="TextBox2" runat="server" MaxLength="4" Text="0"></asp:TextBox>            
    <br />
    <asp:Button ID="Button1" runat="server" Text="PostBack Button" />
    <br />
    <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/" >Redirect Link</asp:HyperLink>

</form>

protected void Page_Load(object sender, EventArgs e) {
    int counter = 0;
    this.Literal1.Text = (this.Page.IsPostBack) ? 

        "Page is postback!" : "This is new request without postback";

    if (this.Page.Session != null) {
        if (this.Page.Request.Cookies[this.Page.Session.SessionID] != null) {
            this.TextBox1.Text = 

                this.Page.Request.Cookies[this.Page.Session.SessionID].Value;
        }
        if (this.Page.Session["SequenceEventCounter"] != null) {
            this.TextBox2.Text = 

                this.Page.Session["SequenceEventCounter"]).ToString();
                counter = (int)this.Page.Session["SequenceEventCounter"];
        }
        this.Page.Session["SequenceEventCounter"] = (int)(++counter);
    }

    HttpCookie cookie = new HttpCookie( 

        HttpContext.Current.Session.SessionID, counter.ToString());
    HttpContext.Current.Response.AppendCookie(cookie);

}


Keine Kommentare:

Kommentar veröffentlichen