在后台代码上设置Cookie [英] Setting Cookies On Code Behind

查看:63
本文介绍了在后台代码上设置Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从一个网站导航到另一个网站
即,
如果以下是我当前的页面
http://www.eggheadcafe.com/ForumPostSubmission.aspx
我想在链接按钮中导航到以下内容,点击
http://aspdotnetcode.source-of-humor.com/Articles/Cookies/UsingCookiesInASPNet-ReadWriteDeleteCookies.aspx
如果第二个有登录名,那么我该怎么做.
即它需要id,工作人员姓名,公司,级别才能进入........
我用以下方式

i want to navigate from one website to another
ie,
if the following is my current page
http://www.eggheadcafe.com/ForumPostSubmission.aspx
i want to navigate to the following in a linkbutton Click
http://aspdotnetcode.source-of-humor.com/Articles/Cookies/UsingCookiesInASPNet-ReadWriteDeleteCookies.aspx
if the second one having a login,then what can i do to implement this.
ie it needs id,staffname,company,level to get in..........
I used the following way

HttpCookie ID = new HttpCookie("id");
                ID.Value = opjn.stringEncode("136");
                Response.Cookies.Add(ID);
                HttpCookie STAFFNAME = new HttpCookie("staffname");
                STAFFNAME.Value = opjn.stringEncode("Johnny");
                Response.Cookies.Add(STAFFNAME);
                HttpCookie LEVEL = new HttpCookie("level");
                LEVEL.Value = opjn.stringEncode("3");
                Response.Cookies.Add(ID);
                HttpCookie COMPANY = new HttpCookie("company");
                COMPANY.Value = opjn.stringEncode("54");
                Response.Cookies.Add(ID);


Response.Redirect(ConfigurationManager.AppSettings["Portal"] + "/aspdotnetcode.source-of-humor.com/Articles/Cookies/UsingCookiesInASPNet-ReadWriteDeleteCookies.aspx", false);


它无法正确设置Cookie
表单身份验证用于第二次网站登录


请帮助我


Its not setting cookies properly
Forms Authentication is used for the second website login


Please help me

推荐答案

首先,我想这只是您的示例,它多次添加了ID Cookie,而不是LEVEL和COMPANY,不是真实的代码?其次,考虑使用 HttpCookie.Domain 属性(也可能是Path属性)来设置cookie有效的域.否则,将使用当前域和路径
First, I guess it is just your example that adds ID cookie multiple times instead of LEVEL and COMPANY, not real code? Second, consider using HttpCookie.Domain property (maybe Path property as well) to set domain for which cookie is valid. Otherwise current domain and path are used


这篇关于在后台代码上设置Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆