Passing the Session object as a reference

I wanted to pass the Session object to a method but received an error message:

A property or indexer may not be passed as an out or ref parameter

int result = something.ValidateUser("someIP","someuser","somepass","somemodule", ref Session, out ErrorText);

Alright. So I tried this:

int result = something.ValidateUser("someIP","someuser","somepass","somemodule", Session, out ErrorText);

Which I accepted like this:

public int ValidateUser(string UserHostAddress, string UserName, string UserPassword, string ServiceCode, System.Web.SessionState.HttpSessionState MySession, out string ErrorText)



MySession["my_incredibly_precious_variable"] = "some value";

And then, outside this method, in my main:

Session["my_incredibly_precious_variable"] was indeed holding "some value".

How is this possible? And most importatnly: is this PROPER?

I couldn't pass Session as a reference or out, so I'm not sure I should be doing this?

Thanks in advance!

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

HttpContext.Current.Session or Page.Session hold the same HttpSessionState object, you don't need to pass it by reference and this is correct.
You can change
MySession["my_incredibly_precious_variable"] = "some value";
HttpContext.Current.Session["my_incredibly_precious_variable"] = "some value";
and you don't need to pass HttpSessionState object as a parameter at all.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Kyanzes, the simple answer is that by default you are passing by reference whenever you pass an object.

As bklmnsh indicates, within the ASP.NET application there should be no need to pass the Session, as it persists and can be accessed elsewhere.
KyanzesAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.