다음을 통해 공유


CookieParameter.CookieName 속성

정의

매개 변수가 바인딩된 HTTP 쿠키의 이름을 가져오거나 설정합니다.

public:
 property System::String ^ CookieName { System::String ^ get(); void set(System::String ^ value); };
public string CookieName { get; set; }
member this.CookieName : string with get, set
Public Property CookieName As String

속성 값

String

매개 변수가 바인딩된 클라이언트측 HTTP 쿠키를 식별하는 문자열입니다.

예제

다음 코드 예제에는 선언적으로 사용 하는 방법을 보여 줍니다.는 SqlDataSource 컨트롤 및 CookieParameter 개체가 바인딩된 HTTP 쿠키를 Northwind 데이터베이스에서 데이터를 표시 하는 GridView 컨트롤입니다.

<%@Page  Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

void Page_Load(Object sender, EventArgs e){
  // These cookies might be added by a login form.
  // They are added here for simplicity.
  if (!IsPostBack) {
      Response.Cookies.Add(new HttpCookie("lname",    "davolio"));
      Response.Cookies.Add(new HttpCookie("loginname","ndavolio"));
      Response.Cookies.Add(new HttpCookie("lastvisit", DateTime.Now.ToString()));
  }
}


</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <asp:SqlDataSource
          id="SqlDataSource1"
          runat="server"
          DataSourceMode="DataSet"
          ConnectionString="<%$ ConnectionStrings:MyNorthwind%>"
          SelectCommand = "SELECT OrderID,CustomerID,OrderDate,RequiredDate,ShippedDate 
                           FROM Orders WHERE EmployeeID = 
                           (SELECT EmployeeID FROM Employees WHERE LastName = @lastname)">
          <SelectParameters>
            <asp:CookieParameter Name="lastname" CookieName="lname" />
          </SelectParameters>
      </asp:SqlDataSource>

      <asp:GridView
          id="GridView1"
          runat="server"
          AllowSorting="True"
          DataSourceID="SqlDataSource1">
      </asp:GridView>

    </form>
  </body>
</html>
<%@Page  Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

Sub Page_Load(sender As Object, e As EventArgs)
  ' These cookies might be added by a login form.
  ' They are added here for simplicity.
  If (Not IsPostBack) Then
      Dim cookie As HttpCookie

      cookie = New HttpCookie("lname","davolio")
      Response.Cookies.Add(cookie)

      cookie = New HttpCookie("loginname","ndavolio")
      Response.Cookies.Add(cookie)

      cookie = New HttpCookie("lastvisit", DateTime.Now.ToString())
      Response.Cookies.Add(cookie)
  End If
End Sub ' Page_Load
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <asp:SqlDataSource
          id="SqlDataSource1"
          runat="server"
          DataSourceMode="DataSet"
          ConnectionString="<%$ ConnectionStrings:MyNorthwind%>"
          SelectCommand = "SELECT OrderID,CustomerID,OrderDate,RequiredDate,ShippedDate 
                           FROM Orders WHERE EmployeeID = 
                           (SELECT EmployeeID FROM Employees WHERE LastName = @lastname)">
          <SelectParameters>                 
            <asp:CookieParameter Name="lastname" CookieName="lname" />
          </SelectParameters>
      </asp:SqlDataSource>

      <asp:GridView
          id="GridView1"
          runat="server"
          AllowSorting="True"
          DataSourceID="SqlDataSource1">
      </asp:GridView>

    </form>
  </body>
</html>

다음 코드 예제에는 프로그래밍 방식으로 만드는 방법을 보여 줍니다는 CookieParameter 개체 속성을 설정 하 고 추가 된 SqlDataSource 컨트롤의 SelectParameters 컬렉션입니다.

public partial class cookieparam2cs_aspx : System.Web.UI.Page 
{
    void Page_Load(Object sender, EventArgs e)
    {
        // These cookies might be added by a login form.
        // They are added here for simplicity.
        if (!IsPostBack)
        {
            Response.Cookies.Add(new HttpCookie("lname", "davolio"));
            Response.Cookies.Add(new HttpCookie("loginname", "ndavolio"));
            Response.Cookies.Add(new HttpCookie("lastvisit", DateTime.Now.ToString()));

            // You can add a CookieParameter to the SqlDataSource control's
            // SelectParameters collection programmatically.
            CookieParameter cookieParam = new CookieParameter();
            cookieParam.Name = "lastname";
            cookieParam.Type = TypeCode.String;
            cookieParam.CookieName = "lname";

            SqlDataSource1.SelectParameters.Add(cookieParam);
        }
    }
}
Partial Class cookieparam2vb_aspx
    Inherits System.Web.UI.Page
    Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        ' These cookies might be added by a login form.
        ' They are added here for simplicity.
        If (Not IsPostBack) Then
            Dim cookie As HttpCookie

            cookie = New HttpCookie("lname", "davolio")
            Response.Cookies.Add(cookie)

            cookie = New HttpCookie("loginname", "ndavolio")
            Response.Cookies.Add(cookie)

            cookie = New HttpCookie("lastvisit", DateTime.Now.ToString())
            Response.Cookies.Add(cookie)


            ' You can add a CookieParameter to the SqlDataSource control's
            ' SelectParameters collection programmatically.
            Dim cookieParam As New CookieParameter()
            cookieParam.Name = "lastname"
            cookieParam.Type = TypeCode.String
            cookieParam.CookieName = "lname"

            SqlDataSource1.SelectParameters.Add(cookieParam)

        End If
    End Sub
End Class

설명

합니다 CookieName 속성으로 표현 되는 HTTP 쿠키를 식별 하는 HttpCookie 개체를 통해 현재 사용할 수 있습니다 HttpRequest 개체입니다. HTTP 쿠키를 현재에서 사용할 수 없으면 HttpRequest 개체를 Evaluate 메서드 매개 변수 값에 바인딩합니다는 DefaultValue 속성에 설정 된 경우. 경우는 DefaultValue 속성을 설정 하지 않으면는 Evaluate 매개 변수 값에 바인딩할 메서드가 실패 합니다.

적용 대상