如何在C#ASP.NET中调用Global.asax值 [英] How to call Global.asax value in C# ASP.NET
本文介绍了如何在C#ASP.NET中调用Global.asax值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的global.asax的VB代码:-
This is my VB code for global.asax :-
<%@ Application Language="VB" %>
<script runat="server">
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs on application startup
Application("CS") = "server=myServer; user id=myUser; password=MyPaas; database=myData; pooling=true;"
End Sub
Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs on application shutdown
Application("CS") = ""
End Sub
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when an unhandled error occurs
End Sub
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when a new session is started
End Sub
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when a session ends.
' Note: The Session_End event is raised only when the sessionstate mode
' is set to InProc in the Web.config file. If session mode is set to StateServer
' or SQLServer, the event is not raised.
End Sub
</script>
我在VB中将此值称为:-Dim objConn As New SqlConnection(Application("CS"))
然后如何在C#中调用ASP.NET
I call this value in VB as :- Dim objConn As New SqlConnection(Application("CS"))
Then how its call in C# ASP.NET
推荐答案
SqlConnection objConn= new SqlConnection( Application["CS"].ToString());
您可以像这样调用应用程序变量:
Hi,
You can call your application variable like this:
Dim strVal AS String = Application.Item("CS")
--Amit
--Amit
这篇关于如何在C#ASP.NET中调用Global.asax值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文