Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
//this code in new class called utility , not in form load , when i need to write request or response in utility class it never written just "response or request " , i see only httpresponse i need to see just response , I hope that you explain to me in detail what exactly do so there are not mistakes, and execute in utilitys class >>>>>>>> look in Comment below.
 

public class utilitys
{
 
public void createCookie(string cookieName, string[] keys, string[] values, bool expired)
{
 
HttpCookie c = new HttpCookie(cookieName);
if (keys != null)
{
for (int x = 0; x < keys.Length; x++)
c.Values.Add(keys[x], values[x]);
if (!expired)
c.Expires = DateTime.Now.AddYears(5);
}
else
c.Expires = DateTime.Now.AddYears(-5);
// look in this step >>>>>>>
res.Cookies.Add(c);
 

}
 
public string readFromCookies(string cookieName, string key, HttpRequest req)
{
try
{
return req.Cookies[cookieName][key].ToString();
}
catch
{
return null;
}
}
 
public void removeCookie(string cookieName, HttpResponse res)
{
// and look in this step >>>>>>>>>>>>>>>
createCookie(cookieName, null, null, false, res);
 
}
 

 
}</pre>
Posted 12-Jul-13 19:04pm
Edited 12-Jul-13 20:24pm
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

you can replace res with HttpContext.Current.Response in createCookie method
 HttpContext.Current.Response.Cookies.Add(c);
OR
you can add new HttpResponse parameter to the method and pass it to the method as parameter
         public void createCookie(string cookieName, string[] keys, string[] values, bool expired, HttpResponse res)
        {
            HttpCookie c = new HttpCookie(cookieName);
            if (keys != null)
            {
                for (int x = 0; x < keys.Length; x++)
                    c.Values.Add(keys[x], values[x]);
                if (!expired)
                    c.Expires = DateTime.Now.AddYears(5);
            }
            else
                c.Expires = DateTime.Now.AddYears(-5);
            // look in this step >>>>>>>
            res.Cookies.Add(c);
        }
 
  Permalink  
v5
Comments
dongos931 at 13-Jul-13 2:10am
   
realy i you help me thank you very muck
Mahesh Bailwal at 13-Jul-13 3:36am
   
Your Welcome. Please mark this question solved.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 565
1 Maciej Los 359
2 Kornfeld Eliyahu Peter 309
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,303
1 DamithSL 4,764
2 Maciej Los 4,306
3 Kornfeld Eliyahu Peter 3,914
4 Sergey Alexandrovich Kryukov 3,538


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 13 Jul 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100