问题描述
我要dynammically设置FormsAuthentication Cookie名称,例如GUID。我怎么能做到这一点。我可以把它已经改变任何我想要在web.config中。我不能做到这一点在code和dynamically.Please帮助。
I want to set FormsAuthentication cookie name dynammically, for example a guid. how can i do that. I can already change it to whatever I want in web.config. I just can't do it in code and dynamically.Please help.
<authentication mode="Forms">
<forms name="myName" loginUrl="~/Account/Login" defaultUrl="~/Admin/admin" cookieless="UseCookies" slidingExpiration="true" timeout="40320"/>
</authentication>
这是我想这样做的原因是,我有我的在同一主机上的应用程序的多个实例,我不希望他们互相覆盖的Cookie。
The reason that I want to do this is, i have several instances of my application on the same host and i do not want them to overwrite each other's cookies.
推荐答案
您不能在code做到这一点;属性 FormsAuthentication.FormsCookieName 是只读的。我会用在的web.config
配置如下:
You can't do this in code; the property FormsAuthentication.FormsCookieName is readonly. I would use the following configuration in web.config
:
<authentication mode="Forms">
<forms configSource="forms.config" />
</authentication>
然后给应用程序的每个实例自己的 forms.config
:
<forms name="CookieNameForThisInstance" />
这篇关于我可以在asp.net中动态地改变FormsAuthentication饼干的名字吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!