动态会话状态提供 [英] Dynamic session state provider

查看:154
本文介绍了动态会话状态提供的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要动态地改变会话状态提供程序时网页加载。

I wish to change the session state provider dynamically when a web page loads.

在本地,同时发展中,我们使用以下命令:

Locally, while developing, we use the following:

<sessionState mode="InProc" />

但产量code运行是这样的:

But production code runs like this:

<sessionState mode="Custom" customProvider="CustomSessionStateProvider">
  <providers>
    <add name="CustomSessionStateProvider" type="Library.CustomSessionStateProvider" applicationName="AppName" />
  </providers>
</sessionState>

这难道不是有可能改变其供应商将sessionState页面加载之前在运行时使用?这将通过某种配置项的确定:

Is it not possible to change which provider the sessionState uses at runtime before a page loads? It would be determined by some kind of configurable item:

if(Environmental.IsProduction)
{
    // Use custom provider
}
else
{
    // Use InProc
}

我们做每使用环境的不同配置文件,不过这个功能需要在所有环境中使用。

We do use different config files per environment, but this feature needs to be available in all environments.

推荐答案

您可以使用Web配置转换来实现这一目标。

You can use Web Config Transformations to achieve this.

这将允许你指定你的web.config转换部分,并具有该取代生成过程中变换令牌不同的环境单独的文件。

This will allow you to specify transform sections in your web.config and have seperate files for different environments that replace the transform tokens during build.

更多信息:的http:// msdn.microsoft.com/en-us/library/dd465318%28v=vs.100%29.aspx

当你部署一个网站,你经常要在一些设置
  部署的应用程序的Web.config文件是来自不同
  发展Web.config文件。例如,您可能希望禁用
  调试选项和更改连接字符串,使它们指向
  不同的数据库。本主题说明如何建立一个Web.config
  变换是在部署过程中自动应用文件
  为了使修改的Web.config文件中部署的版本。

When you deploy a Web site, you often want some settings in the deployed application's Web.config file to be different from the development Web.config file. For example, you might want to disable debug options and change connection strings so that they point to different databases. This topic explains how to set up a Web.config transform file that is applied automatically during deployment in order to make changes to the deployed versions of Web.config files.

Web.config文件转换为更广泛的组设置的一部分,你
  可以配置自动的部署过程。有关信息
  关于所涉及的设置自动部署任务,
  请参阅以下主题:

Web.config transforms are part of a broader group of settings that you can configure to automate the deployment process. For information about the tasks that are involved in setting up automated deployment, see the following topics:

这篇关于动态会话状态提供的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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