c# - Remove and delete all cookies of my ASP NET c-sharp application -


i need remove , delete cookies of asp net c-sharp application after sent on message email.

i have tried solution without success because have error.

server cannot modify cookies after http headers have been sent. 

in line:

httpcontext.current.response.cookies.add(expiredcookie); 

the message email started regularly.

the google search not me.

anybody know how can resolve this?

can suggest?

can me?

my code below.

thank in advance.

private void expireallcookies() {     if (httpcontext.current != null)     {         int cookiecount = httpcontext.current.request.cookies.count;         (var = 0; < cookiecount; i++)         {             var cookie = httpcontext.current.request.cookies[i];             if (cookie != null)             {                 var cookiename = cookie.name;                 var expiredcookie = new httpcookie(cookiename) { expires = datetime.now.adddays(-1) };                 httpcontext.current.response.cookies.add(expiredcookie);             }         }          httpcontext.current.request.cookies.clear();     } }    ............      {         smtpclient.send(mailmessageplaintext);         expireallcookies();         page.clientscript.registerstartupscript(this.gettype(), "alert", "alert('ok.');window.location='http://...';", true);     }     catch (exception ex)     {         throw (ex);     } 

you can try this

if (request.cookies["id"] != null) {     response.cookies["id"].expires = datetime.now.adddays(-1);    } 

or

session.abandon(); 

abandon() clear session cookie not cookies set manually. if specified cookie doesn't exist return null.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -