Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / February 2006

Tip: Looking for answers? Try searching our database.

ASP.net Subroutines - how is it called?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
BookerW - 15 Feb 2006 18:03 GMT
I have a subroutine called Sub Application_BeginRequest.  It is in my
Global.asax.vb file.   It seems to be called when the application is
launched, but I am not sure how.   i thought somewhere in code you have to
actually use the Application_BeginRequest() parameter to invoke the
subroutine.  Or is this some built in thing that if you name something
Application_beginRequest, the engine knows to use this sub routine?

Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
        gsDataSource = ";Data Source = "
        Dim sApplPhysicalPath As String =
Request.ServerVariables("APPL_PHYSICAL_PATH")
        Dim sDataRelPath As String = "..\data\data.mdb"

        gsDataSource += sApplPhysicalPath & sDataRelPath

       Dim sServerName As String =
LCase(Trim(Request.ServerVariables("SERVER_NAME")))
       ' This line use to read If sServerName = "www.pointe.com" Then
       If sServerName = "graddb.bgt.matown.edu/bt/dev" Then
           'Dim sPathInfo As String =
LCase(Trim(Request.ServerVariables("PATH_INFO")))
           'Dim sDir As String = Left(sPathInfo, InStrRev(sPathInfo, "/"))
           'If sDir = "/bt/dev/" Then
           gbDevelopment = True
           'gsDataSource += sApplPhysicalPath & "..\" & sDataRelPath
           ' removed an end if statement
       Else
           ' This use to read gbDevelopment = True
           gbDevelopment = False
       End If
       'These lines use to read
       'If gbSQLServer Then
       'sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=c:\w\btmsm\bt.mdb"
       'gsConnectionString = "Provider=SQLOLEDB;Data Source=ccm4;Initial
Catalog=BTMSM;Integrated Security=SSPI"
       'Else
       'If gbDevelopment Then
       'gsConnectionString = OLEDB_PROVIDER & "User
ID=gtmbatestdb;Password=" & ADMIN_PASSWORD & ";Data Source=point"
       'Else
       'gsConnectionString = OLEDB_PROVIDER & "User ID=ctmsm;Password=" &
ADMIN_PASSWORD & ";Data Source=point"
       'End If

       ' For Production, use different password and use mprod.cgt.bt.buzz
       ' For Development use mdevl.mgt.gt.buzz

       If gbDevelopment Then
           gsConnectionString = OLEDB_PROVIDER & "User ID=ctmba;Password="
& DB_PASSWORD & ";Data Source=mdevl.cgt.bt.buzz"
       Else
           ' The end of this string use to read DB_PASSWORD and
mdevl.cgt.bt.buzz
           gsConnectionString = OLEDB_PROVIDER & "User ID=ctmba;Password="
& DB_PASSWORD1 & ";Data Source=mprod.cgt.bt.buzz"
       End If

    End Sub
Darren Kopp - 15 Feb 2006 18:13 GMT
It's called automatically whenever an application is loaded into the
pool as far as I know.  This is called only once when loaded, but the
application may be loaded several times (such as when you change the
web.config, or upload a new build of the application, or if the pool
recycles).

HTH,
Darren Kopp
http://blog.secudocs.com/
Phillip Williams - 15 Feb 2006 18:19 GMT
The methods within the global.asax.vb are handlers to events triggered by the
HttpApplication class when a request is made to an ASP.NET web application.  

You would find more details in this article "ASP.NET Application Life Cycle
Overview"  
http://msdn2.microsoft.com/en-us/library/ms178473.aspx

BTW, I am glad you reached a solution for that LDAP query issue you had a
while ago.
Signature

HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com

> I have a subroutine called Sub Application_BeginRequest.  It is in my
> Global.asax.vb file.   It seems to be called when the application is
[quoted text clipped - 55 lines]
>
>     End Sub
Patrice - 15 Feb 2006 18:39 GMT
This is just an event as in a windows forms application (that is code that
is called by the system not that you call explicitely).
This executed actually for each web server request...

Application_Start is used once when the application starts...

You could perhaps store the connection string somewhere (web.config or as an
application variable).

Signature

Patrice

> I have a subroutine called Sub Application_BeginRequest.  It is in my
> Global.asax.vb file.   It seems to be called when the application is
[quoted text clipped - 55 lines]
>
> End Sub
BookerW - 15 Feb 2006 19:39 GMT
Thanks Phillip, Darren, Patrice, all the responses pointed me in the right
direction.  What i was trying to seyup is when aa certain user logs into the
application, i wanted a different set of databse credential accounts to be
used as the OLE DB connection(gsconnection string).  I was trying to figure
out where best to put that logic...

Thanks.....

> This is just an event as in a windows forms application (that is code that
> is called by the system not that you call explicitely).
[quoted text clipped - 67 lines]
> >
> > End Sub
Phillip Williams - 15 Feb 2006 20:29 GMT
You might also consider an alternative approach.  The code that you execute
in this routine seems to be concerned only about whether the application is
running in development or production.  If that is the case you can achieve
that goal using a less costly solution (from a maintenance perspective; you
do not need to recompile the application if your development application
folder or user ID changed).  This can be done using the web.config:

1-  add an AppSettings section in your web.config:
<appSettings file="prod.config">
    <add key="DBConnectionString" value="user id=MyUserID;data
source=MySchema;password=MyPassword;Connection Lifetime=3600" />
</appSettings>  

2-  In the application folder in production, create a file named prod.config
that contains only the appSettings section:
<appSettings>
<add key="DBConnectionString" value="user id=ProdUserID;data
source=ProdSchema;password=ProdUserPwd;Connection Lifetime=3600" />
</appSettings>  

This syntax instructs the ASP.NET engine to overrides the settings specified
in the <appSettings> element of the web.config with the settings in the file
named prod.config.

For more details on the <appSettings> Element:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/g
ngrfappsettingselement.asp


Signature

HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com

> Thanks Phillip, Darren, Patrice, all the responses pointed me in the right
> direction.  What i was trying to seyup is when aa certain user logs into the
[quoted text clipped - 75 lines]
> > >
> > > End Sub
Darren Kopp - 15 Feb 2006 21:49 GMT
Booker,

Wrap it up in a class in the Business Logic Layer.  I agree with
Phillip in putting the strings in the web.config, but I would put both
connection strings in there like so:

<appSettings>
  <add key="DevConnString" value="your development connection string
here" />
  <add key="ProdConnString" value="your production connection string
here" />
</appSettings>

Then in your business logic layer I would do something like (and
forgive me if my VB.Net Syntax is wrong)

Public Class DBHelper
   Public Static Function GetConnectionString() as String
     ' run statements to determine what connection string to use
     ' we'll assume you assign to boolean value isProduction

     If Not isProduction Then
       ' not production, use development
       return ConfigurationSetting.AppSettings("DevConnString")
     Else
       return ConfigurationSettings.AppSettings("ProdConnString")
     End If
  End Function
End Class

The function will return the connection string that is in the
web.config file.  Note that where this class is defined, you need to
import System.Configuration.  Then when you create your connection do
do something like

Dim OleDbConnection as New
OleDbConnection(DBHelper.GetConnectionString())

That will make sure you are using the right connection string
everytime.

HTH,
Darren Kopp
http://blog.secudocs.com/
BookerW - 15 Feb 2006 22:31 GMT
Ok, i will have to chew on both of those.  I am new to the asp.net
environment.  I actually inherited this code, and I am learning on the fly.  
So with those excellent examples, I would need to find out how to correctly
import that system configuration you mentioned.  But I do appreciate the
depth of the sample solution provided... very thorough.

> Booker,
>
[quoted text clipped - 40 lines]
> Darren Kopp
> http://blog.secudocs.com/
Darren Kopp - 16 Feb 2006 00:11 GMT
I don't remember what it is with VB.Net, i think it's something like
Inherits System.Configuration.

Just look at the top of the code behind and look for the keyword before
System or System.Web, etc.

so create a VB code file? I think that's what it's called... Anything
with a .vb extension.  then this

Inherits System
Inherits System.Configuration
Inherits System.Web
.. and so on for whatever you need

namespace Whatever           ' replace whatever with your namespace
(usually the project name)
' put class code here
end namespace

again i don't know if that's the right vb syntax, hopefully it is.
it's the right idea though.  Since you are just starting, here are some
nice sites with good 1.x tutorials.

http://aspnet.4guysfromrolla.com/1.x/
http://samples.gotdotnet.com/quickstart/aspplus/
http://aspalliance.com/articleViewer.aspx?aId=144&pId=
http://aspalliance.com/articles/LearnVBNET.aspx
http://aspalliance.com/articles/LearnASPNET.aspx

-Darren

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.