更改Global.asax中声明的变量 [英] Change variable declared in Global.asax

查看:85
本文介绍了更改Global.asax中声明的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我定义了一个变量"string",该变量在 Global.asax的 Application_start 事件中保存特定服务器的connectionstring属性. 文件.
我应该如何通过编码更改此变量的值.
这样,当用户首次登录时,将显示一个下拉列表,并根据选择的内容分配相应的字符串值.

In my project i have defined a variable ''string'' that holds the connectionstring property of a particular server in the Application_start event of Global.asax file.
How should i change the value of this variable through coding.
So that when a user first login a dropdownlist will appear and based on the choice selected a respective string value will be assigned.

推荐答案

根据您的要求,它不会看起来是一个很好的设计,可以在Application_Start中存储/分配连接字符串值!

Global.asax文件是一个可选文件,用于声明和处理在IIS Web服务器上运行的ASP.NET网站的应用程序和会话级事件以及对象.
Application_Start事件在应用程序首次启动时触发.

如果要在应用程序启动中定义变量字符串",则可以继续进行修改,但是首先将其保留在Application_Start中的用途是什么?

从您需要的是,您必须从下拉列表中获取数据源(由用户选择),然后构造连接字符串,然后在运行时将其用于该会话.由于它是基于用户的,因此没有必要将其保留在应用程序级别.
Based on your requirement, it does not look like a good design to store/assign connectionstring value in your Application_Start!

The Global.asax file is an optional file used to declare and handle application and session-level events and objects for an ASP.NET web site running on an IIS Web Server.
The Application_Start event is fired the first time when an application starts.

If you are defining a ''variable string'' in your application start, you can go ahead and modify it but what''s the use of it keeping in Application_Start at the first place?

From what you need is, you have to get the datasource from dropdown(as selected by user), construct the connection string then at runtime and use it for that session. Since it''s user based, no point in keeping it at application level.


这篇关于更改Global.asax中声明的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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