2

I don't want to show mail id in my application code. I want to give text box and what ever email id I will give it should be stored in web.config file for ever until I change it.

string store= "kumar@gmail.com";
ConfigurationManager.AppSettings["MailId"] = store;
string message1 = ConfigurationManager.AppSettings["MailId"];

<appSettings>
    <add key="aspnet:MaxHttpCollectionKeys" value="2001"/>
    <add key="MailId" value="krishnamohan.p@sun.com" />
</appSettings>
Rahul Nikate
  • 6,192
  • 5
  • 42
  • 54

3 Answers3

7
string MailID = ConfigurationManager.AppSettings["MailId"];

Create a cookie

HttpCookie mailCookie= new HttpCookie("mailCookie");

Add key-values in the cookie

mailCookie.Values.Add("MailID", MailID);

set cookie expiry date-time. Keep it max value.

mailCookie.Expires = DateTime.MaxValue;

Most important, write the cookie to client.

Response.Cookies.Add(mailCookie);

Read the cookie from Request.

HttpCookie mailCookie= Request.Cookies["mailCookie"];
if (mailCookie== null)
{
    //No cookie found or cookie expired.
}

Cookie is found.

if (!string.IsNullOrEmpty(mailCookie.Values["MailID"]))
{
    string MailID= mailCookie.Values["MailID"].ToString();
}
Rahul Nikate
  • 6,192
  • 5
  • 42
  • 54
  • hai how to change mail id . where is text box.how can i change emailid@Rahul Nikate –  Jun 09 '15 at 10:50
1

pseudo code:

Code to ADD cookie

HttpCookie e = new HttpCookie("d");
e.Value = "set-Email-Id";
e.Expires = DateTime.Now.AddDays(30); // expires after 30 days
HttpContext.Current.Response.Cookies.Add(e);

Code to Read ( get ) cookie by it name

HttpCookie ck_d = Request.Cookies["d"];
 if(ck_d!=null)
 {
     // logic here
 }
Satinder singh
  • 10,100
  • 16
  • 60
  • 102
  • i want to store mail id . in this how to store mailid. can u write code form me. lets assume my mail id "krishna@gmail.com"@satinder singh –  Jun 09 '15 at 10:37
  • @RahulNikate: That was pseudo code have already mentioned above, though i updated my answer – Satinder singh Jun 09 '15 at 10:50
0
        HttpCookie Cookie = new HttpCookie("cksunlightitmailid");
        Cookie.Value = txtSunlightitmailid.Text.Trim();
        Cookie.Expires = DateTime.MaxValue; // never expire
        HttpContext.Current.Response.Cookies.Add(Cookie);
        HttpCookie ck_d = Request.Cookies["cksunlightitmailid"];
if (Request.Cookies["cksunlightitmailid"] != null)
        {
            lblSunlightitmailid.Text = "Ur current email id :" + Request.Cookies["cksunlightitmailid"].Value;
            //Or Write ur own code here
        }