asp.net 中儲存 資料庫幾種對象

來源:互聯網
上載者:User

session (會話) 一系列有始有終的動作。資料私人性,會話結束,釋放資源,節省訪問器記憶體

                       易丟失,逾時時間很難確定

                    Session[“鍵名”]=值

cookie是網站儲存到用戶端的少量文本資料

優點:理論可以儲存8K的資料,可以自訂有效期間,不佔用伺服器磁碟空間,穩定性比較好

缺點:易丟失,安全性差

向Cookie寫入資料的C#代碼:

Response.Cookies[“userlgin”].value = “tom”;

讀取用戶端Cookie資料的C#代碼:

string uName = Request.Cookie[“userName”];

Application

cache

xml

檔案

資料庫

VieWState

 

//使用ViewState對象將值儲存起來,此對象的有效範圍為當前頁面都可以存取.最終儲存在用戶端。每次都會進行回送
  //ViewState是StateBag類,可存放的資料類型有 int bool string 或數組 及其他的基礎資料型別 (Elementary Data Type),及arraylist,hashtable,
  //或具有類型轉換器的類型,可以串列的類型
  public string Text
  {
   get
   {
    if(ViewState["value"]==null)
    {
     return String.Empty;
    }
    return (string)ViewState["value"];
   }
   set
   {
    ViewState["value"]=value;
   }
  }

 aspnetdb資料庫 profile個人化配置 成員資格和角色管理

 

Request.Tranfer()

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using BLL;
using System.Data;

public partial class User_Question_Default : System.Web.UI.Page
{
    public int num = 9;
    private string name = "sa";

public string Name
{
  get { return name; }
  set { name = value; }
}
private string email = "@263";

public string Email
{
    get { return email; }
    set { email = value; }

    protected void Page_Load(object sender, EventArgs e)
    {
       
    }

    
    protected void Button1_Click(object sender, EventArgs e)
    {
       Context.Server.Transfer("Default2.aspx", true);
    }
}

 

目標頁面:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class User_Question_Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        User_Question_Default ud = (User_Question_Default)Context.Handler;  // 報錯了, 不影響運行,
      
        Response.Write(ud.Name.ToString());
       // Response.Write(Request.Form["TextBox1"].ToString());  //得到了一個類的對象 , 可以自由操作了
    }
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.