如何在运行时在ASP.NET中更改FormsCookieName [英] How to change FormsCookieName at runtime in ASP.NET

查看:224
本文介绍了如何在运行时在ASP.NET中更改FormsCookieName的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们想让FormsCookiePath的FormsCookieName按照我们的应用程序的每个实例进行更改。我们有一个应用程序在1个服务器/域名上有多个实例。因为这个,我们只能在1个应用程序同时工作,因为cookie会覆盖彼此。



是否有动态方法,例如在Global.asax Application_Start中,更改此名称?这将是有用的,因为我们在每个应用程序中保留许可证名称,可用作CookieName的基础。



我们已经使用Web.config和额外的文件使用以下方法覆盖外部文件中的Web.config值:< appSettings file =Web.AppSettings.Config>



感谢。


div class =h2_lin>解决方案

根据 MSDN ,存储Cookie名称的FormsAuthentication.FormsCookieName属性是只读属性。此属性必须从web.config中读取。



每个实例在web.config中都需要一个单独的名称。建议您在现有的变更管理系统中加入验证Cookie的名称。


We would like to have the FormsCookieName of FormsCookiePath change per instance of our application. We have an application which has multiple instances on 1 server/domainname. Because of this we can only work in 1 application at the same time, since the cookies will overwrite eachother. Same for the Sessions btw.

Is there a way to dynamicly, for example in the Global.asax Application_Start, change this name? This would be usefull as we keep a license name in each application which could be used as the basis for the CookieName.

We already work with Web.config and extra files to overwrite Web.config values in external files using: <appSettings file="Web.AppSettings.Config">

But this requires manual actions which can be forgotten and are redundant since the settings can be retrieved from the database.

Thanks.

解决方案

According to MSDN, the FormsAuthentication.FormsCookieName property that stores the cookie name is a read-only property. This property must be read from the web.config.

Each instance will need a separate name in the web.config. I suggest including the name of the authentication cookie in your existing change management system.

这篇关于如何在运行时在ASP.NET中更改FormsCookieName的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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