为什么asp.net 不会在本地主机中创建cookie? [英] Why won't asp.net create cookies in localhost?

查看:19
本文介绍了为什么asp.net 不会在本地主机中创建cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,这真的有点开始困扰我了.我有一个简单的 Web 项目设置,位于:C:ProjectsMyTestProject".在我机器上的 IIS 中,我已经将一个虚拟目录映射到这个位置,这样我就可以在本地运行我的站点(我知道我可以从 Visual Studio 运行它,我更喜欢这种方法).我将这个虚拟目录命名为mtp",并通过 http://localhost/mtp/index.aspx.所有这些都运行良好.

Okay, this is really kinda starting to bug me. I have a simple Web project setup located at: "C:ProjectsMyTestProject". In IIS on my machine, I have mapped a virtual directory to this location so I can run my sites locally (I understand I can run it from Visual Studio, I like this method better). I have named this virtual directory "mtp" and I access it via http://localhost/mtp/index.aspx. All this is working fine.

但是,每当我尝试创建 cookie 时,它​​根本就不会被写出?我已经在 FF3 和 IE7 中尝试过这个,它只是简单地不会写出 cookie.我不明白.我的主机文件中确实有127.0.0.1 localhost",我真的想不出我还能做什么.感谢您的建议.

However, whenever I try to create a cookie, it simply never gets written out? I've tried this in FF3 and IE7 and it just plain won't write the cookie out. I don't get it. I do have "127.0.0.1 localhost" in my hosts file, I can't really think of anything else I can do. Thanks for any advice.

詹姆斯

推荐答案

cookie 规范需要两个名称和一个点,因此您的 cookiedomain 不能是localhost".我是这样解决的:

The cookie specs require two names and a dot between, so your cookiedomain cannot be "localhost". Here's how I solved it:

  1. 将此添加到您的 %WINDIR%System32driversetchosts 文件中:127.0.0.1 dev.livesite.com

  1. Add this to your %WINDIR%System32driversetchosts file: 127.0.0.1 dev.livesite.com

在开发时,您使用 http://dev.livesite.com 而不是 http://localhost

When developing you use http://dev.livesite.com instead of http://localhost

在创建 cookie 时使用.livesite.com"作为 cookiedomain(以点开头).现代浏览器不再需要前导点,但为了向后兼容,您可能希望无论如何都使用.

Use ".livesite.com" as cookiedomain (with a dot in the beginning) when creating the cookie. Modern browsers doesn't require a leading dot anymore, but you may want to use anyway for backwards compability.

现在它适用于所有网站:

Now it works on all sites:

这篇关于为什么asp.net 不会在本地主机中创建cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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