By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,649 Members | 2,142 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,649 IT Pros & Developers. It's quick & easy.

Pasing a reference to my page's Response.Cookies collection

P: n/a
I would like to have my ASPX page call a function intended to make
changes the the current Page.Response.Cookies. I had thought that to
allow the function to modify the Cookies, I would have top pass the
collection by REFERENCE. But I am getting

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

Here is a simple example of what I am trying to do...

public class MyPage: System.Web.UI.Page
{
MySetCookieButton_Click(object sender, ....)
{
CookieFuncs.SetCookies(ref this.Page.Response.Cookies)
}
}

public class CookieFuncs
{
public static void SetCookies(ref System.Web.HttpCookieCollection
cookies)
{
cookies.Value = etc.......
}

}
Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
If you take a look at the class reference, you will find that the Cookies
property of the HttpResponse class is a getter. As indicated by your error
message, you can't pass this by reference. However, make no mistake about
it - you are not doing a deep copy here. If you remove the ref, then you are
no longer trying to pass a reference to the property, but will start passing
the return value of the property - a reference to the cookies collection
that you want. Check out the SDK for a review of which values are passed by
value and which are passed by reference.

--
Chris Jackson
Software Engineer
Microsoft MVP - Windows XP
Windows XP Associate Expert
--
"Scott" <hi********@hotmail.com> wrote in message
news:6a**************************@posting.google.c om...
I would like to have my ASPX page call a function intended to make
changes the the current Page.Response.Cookies. I had thought that to
allow the function to modify the Cookies, I would have top pass the
collection by REFERENCE. But I am getting

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

Here is a simple example of what I am trying to do...

public class MyPage: System.Web.UI.Page
{
MySetCookieButton_Click(object sender, ....)
{
CookieFuncs.SetCookies(ref this.Page.Response.Cookies)
}
}

public class CookieFuncs
{
public static void SetCookies(ref System.Web.HttpCookieCollection
cookies)
{
cookies.Value = etc.......
}

}

Nov 17 '05 #2

P: n/a
"Scott" <hi********@hotmail.com> wrote in message
news:6a**************************@posting.google.c om...
I would like to have my ASPX page call a function intended to make
changes the the current Page.Response.Cookies. I had thought that to
allow the function to modify the Cookies, I would have top pass the
collection by REFERENCE. But I am getting


Just pass Response.Cookies. Objects are already references.
--
John Saunders
Internet Engineer
jo***********@surfcontrol.com

Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.