SQL会话状态服务器动态连接字符串
我正在使用 SQL Server 来实现 ASP.Net 会话状态。但是,我只能在运行时检索连接字符串,因此无法将其存储在 web.config 文件中。通常它会在:
<sessionState
mode="SQLServer"
sqlConnectionString="data source=127.0.0.1;user id=<username>;password=<strongpassword>"
cookieless="false"
timeout="20"
/>
如何在运行时设置连接字符串? (即网络应用程序启动后。)
I am using a SQL Server for ASP.Net session state. However, I am only able to retrieve the connection string at runtime and for that reason cannot store it in the web.config file. Usually it would be in:
<sessionState
mode="SQLServer"
sqlConnectionString="data source=127.0.0.1;user id=<username>;password=<strongpassword>"
cookieless="false"
timeout="20"
/>
How can I set that connection string at runtime? (i.e. after the web app spins up.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否考虑过在 Global.asax 的
Application_Start
事件中执行此操作?这似乎是设置类似内容的合乎逻辑的地方。来自 MSDN 文档:
Have you looked at doing it in the
Application_Start
event inGlobal.asax
? This seems like the logical place to set something like that.From MSDN's documentation:
我认为您可以在 System.Web.SessionState 内的某个位置设置该字符串,希望这将帮助您到达正确的位置。抱歉,我无法给出更好的答案,我仍在尝试自己弄清楚。如果我这样做了,我会让你知道的。 GL
I would think you can set that string somewhere within
System.Web.SessionState
, hopefully that will help you get to the right place. Sorry I can't give a better answer, I'm still trying to figure it out myself. If I do, I'll let you know. GL