请帮忙(动态更改连接字符串) [英] Please help ( changing connection string dynamically )

查看:94
本文介绍了请帮忙(动态更改连接字符串)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web应用程序,该应用程序在同一服务器上具有测试数据库和生产数据库.

我的web.config中有2个不同的连接字符串,一个用于测试数据库,一个用于产品.根据启动页面URL中的查询字符串(\ myapp?test = true)在Session_start事件中选择连接字符串,并将其分配给会话变量.数据层使用此会话变量来访问数据库.

这是问题所在,当会话超时时,应用程序将重定向到登录页面.

在这种情况下,如果最初登录测试数据库的用户尝试重新登录,则将再次触发session_start事件,并且他最初给出的查询字符串将变为null,在这种情况下,连接字符串属于生产数据库,并返回无效的用户错误.

我的session_Start事件是

I have a web application that has a test database and a production database, both on the same server.

I have 2 different connection strings in my web.config, one for the test db and one for the prod. The connection string is selected in the Session_start event based on a querystring (\myapp?test= true ) in the startup page url and assigned to a session variable. The datalayer uses this session variable for accessing the database.

Here is the problem, the application is redirected to the login page when the session time out occurs.

In this scenario if a user originally logged into the test db tries to relogin the session_start event is fired again and the querystring he has originally given becomes null and in that case the connection string is of the production db and an invalid user error is returned.

My session_Start event is

if (Request.querystring["test"] != null)<br />
session["constr"] = testconString;// getting the connectionstring from web.config<br />
else<br />
session["constr"] = prodconString;



谁能给我建议如何解决这个问题.也欢迎采用任何其他方式实现此目标.

预先感谢



Can anyone please advice me on how to solve this problem. Any other way of implementing this is also welcome.

Thanks in advance

推荐答案

也许,如果您使用成员身份,这可以将您重定向到以前的URL?
您可以在登录页面Page.PreviousPage 此处并将其与隐藏字段结合起来!

或使用cookie.
maybe if you use memberships, this can redirect you to previous url?
you can try with property in your login page Page.PreviousPage here and combine it with hidden-field!

or use cookies.


为什么在登录页面链接中未附加默认查询字符串?

喜欢:
//用于生产数据库
http://myownwebsite/Login.aspx?DB = 0
http://myownwebsite/Login.aspx

//用于测试DB
http://myownwebsite/Login.aspx?DB = 1

在您的登录页面中处理querystring.如果值为1,则使用TestDB连接字符串进行连接,否则将进入生产环境.
Why not have a default query string appended to your login page link?

Like:
// for Production DB
http://myownwebsite/Login.aspx?DB=0
http://myownwebsite/Login.aspx

// for test DB
http://myownwebsite/Login.aspx?DB=1

Handle the querystring in your login page. If the value is 1 then connect using TestDB connection string or else go for production one.


这篇关于请帮忙(动态更改连接字符串)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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