我判断用户登录以后
把值赋给 Response.Cookies["name"].Value = janUname.Text;之后呢我有个进去以后
我有个分页页面中有
<A  target="_blank" href='comview.aspx?comID=24410'>但是弹出来的comview.aspx的这个页面就是判断我没有没有登陆这是我判断调用的
public static bool PersonAuthenticated()
 {
     HttpContext context = HttpContext.Current ;
       if(context.Request.Cookies["name"]==null||context.Request.Cookies["name"].Value=="")
{
return false;
}
else
{
return true;
}
}这是为什么,是不是我的Web.config里没有调对?
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
     <appSettings>
      <add key="Forums_SettingsFile" value="Config/Forums.Config" /> 
      <add key="ConnectionString" value="" />
      </appSettings>  <system.web>    <!--  动态调试编译           设置 compilation debug="true" 以启用 ASPX 调试。否则,将此值设置为
          false 将提高此应用程序的运行时性能。
          设置 compilation debug="true" 以将调试符号(.pdb 信息)
          插入到编译页中。因为这将创建执行起来
          较慢的大文件,所以应该只在调试时将此值设置为 true,而在所有其他时候都设置为
          false。有关更多信息,请参考有关
          调试 ASP.NET 文件的文档。
    -->
    <compilation 
         defaultLanguage="c#"
         debug="true"
    />    <!--  自定义错误信息
          设置 customErrors mode="On" 或 "RemoteOnly" 以启用自定义错误信息,或设置为 "Off" 以禁用自定义错误信息。 
          为每个要处理的错误添加 <error> 标记。          "On" 始终显示自定义(友好的)信息。
          "Off" 始终显示详细的 ASP.NET 错误信息。 <error statusCode="404" redirect="PagenotFound.htm" />
          "RemoteOnly" 只对不在本地 Web 服务器上运行的
           用户显示自定义(友好的)信息。出于安全目的,建议使用此设置,以便  defaultRedirect="ErrorPage.htm"
           不向远程客户端显示应用程序的详细信息。defaultRedirect="userError.aspx"<r>
    -->
    <customErrors mode="RemoteOnly" defaultRedirect="error/genericerror.htm"> 
      <error statusCode="404" redirect="error/notfound.aspx" />
<error statusCode="403" redirect="error/noaccess.aspx"/>
    </customErrors>    <!--  身份验证 
          此节设置应用程序的身份验证策略。可能的模式是 "Windows"、 
          "Forms"、 "Passport" 和 "None"          "None" 不执行身份验证。 
          "Windows" IIS 根据应用程序的设置执行身份验证 
            (基本、简要或集成 Windows)。在 IIS 中必须禁用匿名访问。
          "Forms" 您为用户提供一个输入凭据的自定义窗体(Web 页),然后 
           在您的应用程序中验证他们的身份。用户凭据标记存储在 Cookie 中。
          "Passport" 身份验证是通过 Microsoft 的集中身份验证服务执行的,
           它为成员站点提供单独登录和核心配置文件服务。
    -->
    <!--
            identity impersonate="true"
           authentication mode="Forms" 
            <identity impersonate="true" />
           HttpContext  用户提供的名称
           WindowsIdentity 域\用户名
           Thread 用户提供的名称
    -->   <identity impersonate="true" />
    <authentication mode="Forms">
      <forms name="Job" path="/" loginUrl="Login.aspx" protection="All" timeout="30"/>
    </authentication>
     <!--  授权 
           此节设置应用程序的授权策略。可以允许或拒绝不同的用户或角色访问
          应用程序资源。通配符: "*" 表示任何人,"?" 表示匿名
          (未经身份验证的)用户。
    -->   <authorization>
        <allow users="*" /><!-- 允许所有用户 -->
           <!--  <allow     users="[逗号分隔的用户列表]"
                             roles="[逗号分隔的角色列表]"/>
                  <deny      users="[逗号分隔的用户列表]"
                             roles="[逗号分隔的角色列表]"/>
                             <deny users="?"/>使用基于窗体的身份验证的应用程序通常使用这两个特殊的用户名拒绝对未经过身份验证的用户的访问-->
           
              
   </authorization>     <!--  应用程序级别跟踪记录
          应用程序级别跟踪为应用程序中的每一页启用跟踪日志输出。
          设置 trace enabled="true" 可以启用应用程序跟踪记录。如果 pageOutput="true",则
          在每一页的底部显示跟踪信息。否则,可以通过浏览 Web 应用程序
           根目录中的 "trace.axd" 页来查看
          应用程序跟踪日志。
    -->
    <trace
        enabled="false"
        requestLimit="10"
        pageOutput="false"
        traceMode="SortByTime"
localOnly="true"
    />    <!--  会话状态设置
          默认情况下,ASP.NET 使用 Cookie 来标识哪些请求属于特定的会话。
          如果 Cookie 不可用,则可以通过将会话标识符添加到 URL 来跟踪会话。
         若要禁用 Cookie,请设置 sessionState cookieless="true"。
    -->
    <sessionState 
            mode="InProc"
            stateConnectionString="tcpip=127.0.0.1:42424"
            sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
            cookieless="false" 
            timeout="20" 
    />    <!--  全球化
          此节设置应用程序的全球化设置。
            requestEncoding="utf-8" 
            responseEncoding="utf-8" 
             
    -->
    <globalization 
           requestEncoding="gb2312" 
          responseEncoding="gb2312"  
           
   />
   
 </system.web></configuration>

解决方案 »

  1.   

    那是怎么回事,我有个DataGrid的分页,
    要弹出很多资料,如果用户登录了,还看不了,我要他还有什么用。
      

  2.   

    <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="study.WebForm1" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>WebForm1</title>
    <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" Content="C#">
    <meta name="vs_defaultClientScript" content="JavaScript">
    <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    </HEAD>
    <body MS_POSITIONING="GridLayout">
    <form id="Form1" method="post" runat="server">
    <FONT face="宋体">
    <asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 280px; POSITION: absolute; TOP: 80px" runat="server"></asp:TextBox>
    <asp:TextBox id="TextBox2" style="Z-INDEX: 102; LEFT: 280px; POSITION: absolute; TOP: 128px"
    runat="server"></asp:TextBox>
    <asp:Button id="Button1" style="Z-INDEX: 103; LEFT: 328px; POSITION: absolute; TOP: 168px" runat="server"
    Text="Button"></asp:Button>
    <asp:Button id="Button2" style="Z-INDEX: 104; LEFT: 424px; POSITION: absolute; TOP: 176px" runat="server"
    Text="Button"></asp:Button></FONT>
    </form>
    </body>
    </HTML>using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;namespace study
    {
    /// <summary>
    /// WebForm1 的摘要说明。
    /// </summary>
    public class WebForm1 : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.TextBox TextBox1;
    protected System.Web.UI.WebControls.TextBox TextBox2;
    protected System.Web.UI.WebControls.Button Button2;
    protected System.Web.UI.WebControls.Button Button1;

    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    } #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.Button1.Click += new System.EventHandler(this.Button1_Click);
    this.Button2.Click += new System.EventHandler(this.Button2_Click);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void Button1_Click(object sender, System.EventArgs e)
    {
    Response.Cookies["name"].Value = TextBox1.Text;
    } private void Button2_Click(object sender, System.EventArgs e)
    {
    TextBox2.Text = (string)Request.Cookies["Name"].Value.ToString();
    }
    }
    }我测试的没有问题!!
      

  3.   

    我说得是弹出页面 不是本页<A  target="_blank" href='comview.aspx?comID=24410'>就是弹出的页面
      

  4.   

    写入
    HttpCookie cookie=new HttpCookie("mycookie");
    cookie.Values.Add("name",janUname.Text);
    cookie.Expires=DateTime.Now.AddDays(天数);
    Response.AppendCookie(cookie);//注意这句
    读取
    if(Request.Cookies["mycookie"]==null)
    {
    return false;
    }
    else
    {
    return true;
    }
      

  5.   

    /// <summary>
    /// savecookie
    /// </summary>
    /// <param name="e">CookieName,CookieValue</param>
    private void SaveCookie(string CookieName,string CookieValue)
    {
    HttpCookie myCookie = new HttpCookie(CookieName);
    DateTime now = DateTime.Now; myCookie.Value = CookieValue; myCookie.Expires = now.AddHours(3);
    if(this.Response.Cookies[CookieName]!=null)
    this.Response.Cookies.Remove(CookieName); this.Response.Cookies.Add(myCookie);
    }/// <summary>
    /// getcookie
    /// </summary>
    /// <param name="CookieName"></param>
    /// <returns>cookievalue</returns>
    private string GetCookie(string CookieName)
    {
    HttpCookie myCookie = new HttpCookie(CookieName);
    myCookie = Request.Cookies[CookieName]; if (myCookie != null)
    return myCookie.Value;
    else
    return null;
    }调用
    SaveCookie("user","true");
    GetCookie("user")
      

  6.   

    HttpCookie tmpCookie=new HttpCookie("key","value");
    Response.Cookies.Add(tmpCookie);和session的用法是有区别的.
      

  7.   

    不过如果只是保存用户名完全没必要这么做.
    using System.Web.Security;    FormsAuthentication.RedirectFromLoginPage(username, createPersistentCookie);
        FormsAuthentication.SetAuthCookie(username, createPersistentCookie);
    用上面这两个东东可以给你建立当前用户的身份cookie,第二个参数表示是否建立永久cookie.
    前一种方法具有自动转向功能,如果在default页面登陆那只能转到default页面,如果试图去访问一个需要身份验证的页面a.aspx则会转到login.aspx页面,登陆成功后前者会自动转到a.aspx页面,用后者你自己需要写代码转向
           
     HttpContext.Current.User.Identity.Name
    这个东东可以获取当前登陆的用户名.
      

  8.   

    写入COOKIE用 Response,读取用 Request
      

  9.   

    是不是我要有两个值就是这么写HttpCookie nameCookie=new HttpCookie("name",name);
    Response.Cookies.Add(nameCookie);HttpCookie personIDCookie=new HttpCookie("personID",personID.ToString());
    Response.Cookies.Add(personIDCookie);我还有个问题就是下面这种写法和和上面这种写法有什么区别?
    除了下面的是自己设置cookie的有效期,
    Response.AppendCookie和Response.Cookies.Add有什么区别??
    =========================================================HttpCookie cookie=new HttpCookie("name");
    cookie.Values.Add("name",name);
    cookie.Expires=DateTime.Now.AddHours(1);
    Response.AppendCookie(cookie);HttpCookie personIDcookie=new HttpCookie("personID");
    personIDcookie.Values.Add("personID",personID.ToString());
    personIDcookie.Expires=DateTime.Now.AddHours(1);
    Response.AppendCookie(personIDcookie);
      

  10.   

    按照第2种方法
    还就是我对读取的时候总是
    int.Parse(Request.Cookies["personID"].Value));
    输入字符串的格式不正确
      

  11.   

    HttpCookie cookie=new HttpCookie("mycookie");
    cookie.Values.Add("name","zhuye");
    cookie.Values.Add("age","20");
    Response.AppendCookie(cookie);
    两个值就这么写读取的时候
    HttpCookie cookie=Request.Cookies["mycookie"];
    string name=cookie.Values["name"];
    string age=cookie.Values["age"];//cookie只保存字符串类型
      

  12.   

    HttpCookie personIDcookie=new HttpCookie("personID");
    personIDcookie.Values.Add("",newUser.UserID.ToString());
    //我把他为空了,"",好像就没事了
    personIDcookie.Expires=DateTime.Now.AddHours(1);
    Response.AppendCookie(personIDcookie);
    我在问一下,
    int.Parse(Request.Cookies["personID"].Value)
    我这样就没事了
      

  13.   

    cookie集合内可以放多个Value,为什么你就一定要一个Value一个cookie集合呢?按照我写的方法做吧
      

  14.   

    大哥,不是我不按照你的方法来。
    而是我要是按你的方法来的话呢我就要最少该200个页
    我以前都是int.Parse(Request.Cookies["personID"].Value)
    这么取得,你觉得怎么样?
    personIDcookie.Values.Add("",newUser.UserID.ToString());
    这一句没事吧要不然的话Request.Cookies["personID"].Value的值就是personID=3了
    而不是3
      

  15.   

    to: LoveCherry我这种也没事吧
      

  16.   

    这个是客户端的问题,它没有向弹出的新浏览器实例传递Cookie,这里面的原因很多,和系统的一些设置有关,也和你打开新窗口的方法有关。你是用什么方法打开新窗口?