How in code to detect if session is enabled rather than just get an error
up vote
1
down vote
favorite
If I set
@ENABLESESSIONSTATE = false
then
session("foo") = "bar"
then the result is
Microsoft VBScript runtime error '800a0114'
Variable is undefined 'Session'
... file and line no
It would usually indicate a mistaken assumption regarding program flow and I would trace and fix the issue.
However, in a specific set of circumstances I have a case where a piece of code that uses session is always invoked first on every page request. It is to do with performance monitoring.
This code includes a fork - if the user has a session we go one way, if not we go another.
But of course where the users session is absent because we introduced some code that runs with session disabled, we get the crash.
I could solve it with
on error resume next
session("foo") = "bar"
if err.number <> 0 then
' do the no-has-session fork
else
' do the has-session fork
end if
on error goto 0
But I wondered if there is a less hacky approach.
session vbscript asp-classic session-variables
add a comment |
up vote
1
down vote
favorite
If I set
@ENABLESESSIONSTATE = false
then
session("foo") = "bar"
then the result is
Microsoft VBScript runtime error '800a0114'
Variable is undefined 'Session'
... file and line no
It would usually indicate a mistaken assumption regarding program flow and I would trace and fix the issue.
However, in a specific set of circumstances I have a case where a piece of code that uses session is always invoked first on every page request. It is to do with performance monitoring.
This code includes a fork - if the user has a session we go one way, if not we go another.
But of course where the users session is absent because we introduced some code that runs with session disabled, we get the crash.
I could solve it with
on error resume next
session("foo") = "bar"
if err.number <> 0 then
' do the no-has-session fork
else
' do the has-session fork
end if
on error goto 0
But I wondered if there is a less hacky approach.
session vbscript asp-classic session-variables
2
You could wrap the logic in a function to make easier to work with, but as for the approach of checking using OERN this would be what I would do. Wonder though, could you not perhaps do aIsObject(Session)
check?
– Lankymart
10 hours ago
Had not considered that - might still throw an error in being undefined though. I'll try it and post back.
– Vanquished Wombat
9 hours ago
Possible duplicate of Check if an Object exists in VBScript
– Lankymart
6 hours ago
Lankymart is right. Doif isobject(session) then session("foo") = "bar" end if
– Daniel Blais
5 hours ago
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
If I set
@ENABLESESSIONSTATE = false
then
session("foo") = "bar"
then the result is
Microsoft VBScript runtime error '800a0114'
Variable is undefined 'Session'
... file and line no
It would usually indicate a mistaken assumption regarding program flow and I would trace and fix the issue.
However, in a specific set of circumstances I have a case where a piece of code that uses session is always invoked first on every page request. It is to do with performance monitoring.
This code includes a fork - if the user has a session we go one way, if not we go another.
But of course where the users session is absent because we introduced some code that runs with session disabled, we get the crash.
I could solve it with
on error resume next
session("foo") = "bar"
if err.number <> 0 then
' do the no-has-session fork
else
' do the has-session fork
end if
on error goto 0
But I wondered if there is a less hacky approach.
session vbscript asp-classic session-variables
If I set
@ENABLESESSIONSTATE = false
then
session("foo") = "bar"
then the result is
Microsoft VBScript runtime error '800a0114'
Variable is undefined 'Session'
... file and line no
It would usually indicate a mistaken assumption regarding program flow and I would trace and fix the issue.
However, in a specific set of circumstances I have a case where a piece of code that uses session is always invoked first on every page request. It is to do with performance monitoring.
This code includes a fork - if the user has a session we go one way, if not we go another.
But of course where the users session is absent because we introduced some code that runs with session disabled, we get the crash.
I could solve it with
on error resume next
session("foo") = "bar"
if err.number <> 0 then
' do the no-has-session fork
else
' do the has-session fork
end if
on error goto 0
But I wondered if there is a less hacky approach.
session vbscript asp-classic session-variables
session vbscript asp-classic session-variables
edited 3 hours ago
Lankymart
11.4k43896
11.4k43896
asked 18 hours ago
Vanquished Wombat
3,48811034
3,48811034
2
You could wrap the logic in a function to make easier to work with, but as for the approach of checking using OERN this would be what I would do. Wonder though, could you not perhaps do aIsObject(Session)
check?
– Lankymart
10 hours ago
Had not considered that - might still throw an error in being undefined though. I'll try it and post back.
– Vanquished Wombat
9 hours ago
Possible duplicate of Check if an Object exists in VBScript
– Lankymart
6 hours ago
Lankymart is right. Doif isobject(session) then session("foo") = "bar" end if
– Daniel Blais
5 hours ago
add a comment |
2
You could wrap the logic in a function to make easier to work with, but as for the approach of checking using OERN this would be what I would do. Wonder though, could you not perhaps do aIsObject(Session)
check?
– Lankymart
10 hours ago
Had not considered that - might still throw an error in being undefined though. I'll try it and post back.
– Vanquished Wombat
9 hours ago
Possible duplicate of Check if an Object exists in VBScript
– Lankymart
6 hours ago
Lankymart is right. Doif isobject(session) then session("foo") = "bar" end if
– Daniel Blais
5 hours ago
2
2
You could wrap the logic in a function to make easier to work with, but as for the approach of checking using OERN this would be what I would do. Wonder though, could you not perhaps do a
IsObject(Session)
check?– Lankymart
10 hours ago
You could wrap the logic in a function to make easier to work with, but as for the approach of checking using OERN this would be what I would do. Wonder though, could you not perhaps do a
IsObject(Session)
check?– Lankymart
10 hours ago
Had not considered that - might still throw an error in being undefined though. I'll try it and post back.
– Vanquished Wombat
9 hours ago
Had not considered that - might still throw an error in being undefined though. I'll try it and post back.
– Vanquished Wombat
9 hours ago
Possible duplicate of Check if an Object exists in VBScript
– Lankymart
6 hours ago
Possible duplicate of Check if an Object exists in VBScript
– Lankymart
6 hours ago
Lankymart is right. Do
if isobject(session) then session("foo") = "bar" end if
– Daniel Blais
5 hours ago
Lankymart is right. Do
if isobject(session) then session("foo") = "bar" end if
– Daniel Blais
5 hours ago
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
You should be able to determine if the Session
object is present using the VBScript function IsObject()
.
If IsObject(Session) Then Session("foo") = "bar"
This could also become cumbersome to maintain, but you could take it a step further and build a wrapper for setting the Session keys;
Sub SetSessionValue(key, value)
If IsObject(Session) Then Session(key) = value
End Sub
Usage:
Call SetSessionValue("foo", "bar")
This is just a basic example but should give you are starting point to work from.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
You should be able to determine if the Session
object is present using the VBScript function IsObject()
.
If IsObject(Session) Then Session("foo") = "bar"
This could also become cumbersome to maintain, but you could take it a step further and build a wrapper for setting the Session keys;
Sub SetSessionValue(key, value)
If IsObject(Session) Then Session(key) = value
End Sub
Usage:
Call SetSessionValue("foo", "bar")
This is just a basic example but should give you are starting point to work from.
add a comment |
up vote
0
down vote
You should be able to determine if the Session
object is present using the VBScript function IsObject()
.
If IsObject(Session) Then Session("foo") = "bar"
This could also become cumbersome to maintain, but you could take it a step further and build a wrapper for setting the Session keys;
Sub SetSessionValue(key, value)
If IsObject(Session) Then Session(key) = value
End Sub
Usage:
Call SetSessionValue("foo", "bar")
This is just a basic example but should give you are starting point to work from.
add a comment |
up vote
0
down vote
up vote
0
down vote
You should be able to determine if the Session
object is present using the VBScript function IsObject()
.
If IsObject(Session) Then Session("foo") = "bar"
This could also become cumbersome to maintain, but you could take it a step further and build a wrapper for setting the Session keys;
Sub SetSessionValue(key, value)
If IsObject(Session) Then Session(key) = value
End Sub
Usage:
Call SetSessionValue("foo", "bar")
This is just a basic example but should give you are starting point to work from.
You should be able to determine if the Session
object is present using the VBScript function IsObject()
.
If IsObject(Session) Then Session("foo") = "bar"
This could also become cumbersome to maintain, but you could take it a step further and build a wrapper for setting the Session keys;
Sub SetSessionValue(key, value)
If IsObject(Session) Then Session(key) = value
End Sub
Usage:
Call SetSessionValue("foo", "bar")
This is just a basic example but should give you are starting point to work from.
edited 3 hours ago
answered 3 hours ago
Lankymart
11.4k43896
11.4k43896
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53204393%2fhow-in-code-to-detect-if-session-is-enabled-rather-than-just-get-an-error%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
2
You could wrap the logic in a function to make easier to work with, but as for the approach of checking using OERN this would be what I would do. Wonder though, could you not perhaps do a
IsObject(Session)
check?– Lankymart
10 hours ago
Had not considered that - might still throw an error in being undefined though. I'll try it and post back.
– Vanquished Wombat
9 hours ago
Possible duplicate of Check if an Object exists in VBScript
– Lankymart
6 hours ago
Lankymart is right. Do
if isobject(session) then session("foo") = "bar" end if
– Daniel Blais
5 hours ago