ASP Issue: Is it possible to pass session variables as parameters to functions in the Global.asa file?

StackOverflow https://stackoverflow.com/questions/10250992

سؤال

I plan to write the Global.asa file in JavaScript. When a session or application ends, I need changes to be made in a database. Specifically, I need to break up a string and use it in a query in the Global.asa functions. That part doesn't puzzle me at all. Just the part about passing a session variable in as a parameter. I imagine my Global.asa to look something like this:

(Let's say the two variables "variable1" and "variable2" were session variables)

<script language="JScript" runat="Server">
function Application_OnStart() {
}

function Application_OnEnd(variable1) {
}

function Session_OnStart() {
}

function Session_OnEnd(variable2) {
}
</script>

So, I'm not sure if what I'm asking is even feasible. If so, any tips? Keep in mind that I am working in ASP, not ASP.NET. Also, I'm a bit new to using server-side code, so pardon my ignorance.

هل كانت مفيدة؟

المحلول

No, what you suggest is not feasible.

The functions in the global.asa file are callbacks for events. The functions get called, all with no parameters.

You can make use of the Session object to do what you want.

In your code you can set a session variable like this:

session("userid") = 856

In your global.asa you can then use:

variable1 = session("userid")

نصائح أخرى

Have you considered using VBScript for your Global.asa? I've never coded a Global.asa in javascript, but you could code it in VB and use Session or Application level variables:

<SCRIPT LANGUAGE=VBScript RUNAT=Server>

Sub Application_OnStart()
    'initialize application level variables
    Application("ConnectionString") = "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.mappath("access_db/mydb.mdb")
End Sub

Sub Application_OnEnd()
    Application("ConnectionString") = ""
End Sub

Sub Session_OnStart()
    'initialize session level variables
    Session("UserIP") = Request.ServerVariables("REMOTE_ADDR")
End Sub

Sub Session_OnEnd()
    Session("UserIP") = ""
End Sub

Not sure if you can pass a variable into the predefined functions as such, but you can use Session or Application variables anywhere on the website, including within these functions.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top