ASPXAUTH cookie is not being saved

久未见 提交于 2020-01-02 03:41:26

问题


Im working on a web project in ASP .NET MVC 2.

In this project we store some info inside an ecripted cookie (the ASPXAUTH cookie) to avoid the need to query the db for every request.

The thing is the code for this part has suddenly stopped working.

I reviewed the changes made to the code on the source control server for anything that could be causing it, I found nothing. I even reverted to a known working copy (working on some other persons PC, same code, etc) but after debugging, it seems the .ASPXAUTH cookie is not getting saved anymore. Instead the ASP.NET_SessionId cookie is being set... (wich before wasn't)

I changed the web.config file to turn off the sessionState. This eliminated the ASP.NET_SessionId cookie from being set, but it is still not saving the auth cookie.

Ive recently installed some Microsoft Windows XP Updates, but the other person (whos PC runs the application just fine) also did.

After googling, some info i found pointed out to a problem with the expiration date of the cookie. Ether cus the pc didnt have the right time/date (this was not the case) and others cus of the cookie expiration date being wrongly set. (I checked and it is being set correctly)...

The problem persists with other browsers besides the one im using (Chrome) i tried it with IE6.

Any ideas on why this is happening?

Ill continue to post any helpful information i can find.

Thanks in advance.


回答1:


This could be that your cookie grew too big. I ran into the same issue. If your cookie becomes too big, it just won't work, depending on the browser of course

MSDN

cookies are usually limited to 4096 bytes and you can't store more than 20 cookies per site. By using a single cookie with subkeys, you use fewer of those 20 cookies that your site is allotted. In addition, a single cookie takes up about 50 characters for overhead (expiration information, and so on), plus the length of the value that you store in it, all of which counts toward the 4096-byte limit. If you store five subkeys instead of five separate cookies, you save the overhead of the separate cookies and can save around 200 bytes.

What is the maximum size of a web browser's cookie's key?

what happens when cookies file exceeds maximum size?




回答2:


An easy way to check your cookies size is to debug and run the following code

int cookieSize = System.Text.UTF8Encoding.UTF8.GetByteCount(faCookie.Values.ToString());

If this is over the limit then you will be encountering issues.




回答3:


In my case after certain amount of head banging against a wall I noticed in my working projects cookie was set using

FormsAuthentication.SetAuthCookie(user.token, false);

in contrast in my not working projects the cookie was being set manually:

var coockie = FormsAuthentication.GetAuthCookie(user.token, false);
coockie.Expires = DateTime.Now.AddDays(7);

Response.Cookies.Add(coockie);

This happened in one of my shared hostings after some change was made by hosting provider which I could not figure out or find out through support dep. local host or other shared hostings or vps worked just fine with the first approuch



来源:https://stackoverflow.com/questions/1900584/aspxauth-cookie-is-not-being-saved

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!