小编Ric*_*n35的帖子

Asp.NET cookies返回null

当点击一个按钮时,我正试图保存一个cookie ...

protected void btn_login_Click(object sender, EventArgs e)
{
   HttpCookie cookie = new HttpCookie("test");
   cookie["work"] = "now";
   cookie.Expires = DateTime.Now + new TimeSpan(1, 0, 0, 0);
   cookie.Domain = ".cookie.com";
   Response.Cookies.Add(cookie);
}
Run Code Online (Sandbox Code Playgroud)

然后在page_load上我正在阅读cookie ...

protected void Page_Load(object sender, EventArgs e)
{
    string a = Response.Cookies["test"]["work"];
}
Run Code Online (Sandbox Code Playgroud)

但它不断回归无效.我在localhost下运行这个,我读到cookies不会保存在localhost下所以我编辑了我的主机文件说127.0.0.1 test.cookie.com当我用Fiddler查看什么被发布到页面的标题.看起来像这样......

test/work = now test =

所以我可以看到它已经设置但是由于某种原因,当我在其中读取它时返回null.

asp.net cookies

3
推荐指数
2
解决办法
5381
查看次数

NetworkStream正在读取不应该存在的数据

我有一个问题,NetworkStream从套接字缓冲区读取数据不应该存在.顺便说一句,我发送了很大的缓冲区.现在我刚刚在localhost上进行测试.

这是我如何读取数据,前4个字节包含消息的长度,然后我只读取4096个块,直到它达到消息的长度.

    protected TcpClient tcpObject;
    protected NetworkStream tcpStream;

    private void HandleComm()
    {
        try
        {
            tcpStream = tcpObject.GetStream();
            byte[] totalByteAray = new byte[constIntSize];
            byte[] message = new byte[constChunkSize];
            byte[] fullMessage = new byte[0];

            //this is how many bytes long the message will be
            int totalBytes = 0;
            int currentBytes = 0;
            int chunkSize = constChunkSize;

            while (true)
            {
                //skip reading if no data is available
                //DataAvailable does not tell you when all the data has arrived
                //it just tell you if …
Run Code Online (Sandbox Code Playgroud)

c# sockets tcp tcplistener tcpclient

2
推荐指数
1
解决办法
2929
查看次数

标签 统计

asp.net ×1

c# ×1

cookies ×1

sockets ×1

tcp ×1

tcpclient ×1

tcplistener ×1