Click here to Skip to main content
11,705,753 members (46,042 online)
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 18:04pm
Edited 12-Jul-13 19: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 OriginalGriff 213
1 Sergey Alexandrovich Kryukov 170
2 Inimicos 60
3 ProgramFOX 50
4 F-ES Sitecore 45
0 OriginalGriff 9,037
1 Sergey Alexandrovich Kryukov 8,417
2 CPallini 5,189
3 Maciej Los 4,726
4 Mika Wendelius 3,626


Advertise | Privacy | Mobile
Web03 | 2.8.150819.1 | Last Updated 13 Jul 2013
Copyright © CodeProject, 1999-2015
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