asp.net 'Remember me' not working anymore with forms authentication

雨燕双飞 提交于 2020-01-12 02:28:51

问题


I have two websites with self written membership providers that are hostet on the same server in the same Web in different web-applications and different application pools.

Formerly I had the problem, that I could not log on on both sites together. Thanks to Remy's post, this works now, I had to add the name-attribute to the forms element.
But now I have the problem that the remember-me option of the asp login-control stopped to work. The user is logged off after the normal session-timeout.

The authentication-attributes in the web.config file look as follows:

<authentication mode="Forms" >
  <forms loginUrl="~/UserMgmt/Login.aspx" timeout="400000" slidingExpiration="true" name="NameOfTheSite"/>
</authentication>

Also have I set the cookie name for the forms authetication to different names.

Is there something else that I have to add, so that the remember-me feature works?

Update
I have observed that if I disable encryption and validation for the forms authentication-cookie, the problem is gone. If I either activate encryption, validation or both, the problem occurs newly.
I know also, that it's independent of the session-cookie names (they even could be identical). Maybe this information helps someone to figure out what's going on?

Update 1
Thanks to Jason Kealey for the solution to this problem. I would never had found it. In the meantime I've found the corresponding information in msdn. In How To: Configure MachineKey in ASP.NET 2.0 in the section "Web Farm Deployment Considerations" is written:

If you want to isolate your application from other applications on the same server, place the <machineKey> in the Web.config file for each application on each server in the farm. Ensure that you use separate key values for each application, but duplicate each application's keys across all servers in the farm.


回答1:


The issue may be that you have validation keys that are automatically generated every time you launch the worker process. The cookie is encrypted, but when you come back a new server-side key is used and thus your cookie cannot be decrypted.

Check out the machineKey section http://msdn.microsoft.com/en-us/library/ff649308.aspx

Here is something that will generate the machineKey section for you http://www.qualitydata.com/products/aspnet-membership/help/configuration/no-machinekey.aspx




回答2:


Try set the domain name to be sure that the cookie of the remember is set correctly in all cases

<forms  path="/" domain="nameof.com" ...the rest



回答3:


The cookie timeout is also limited by IIS and defaults to something low like 20 min. To change this:

  1. Open IIS Manager.
  2. Right click your site and select properties.
  3. Select the ASP.NET tab and click Edit Configuration.
  4. Select the Authentication tab.
  5. Select Enable sliding expiration.
  6. Set the Cookie timeout to a longer value. To set to 30 days, enter 30.00:00:00.
  7. Click OK and exit IIS manager.



来源:https://stackoverflow.com/questions/4728036/asp-net-remember-me-not-working-anymore-with-forms-authentication

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