Deleting a cookie on asp.net web api -
i'm trying delete session-id cookie
, doesn't work.
any guidance completing task using normal controller? httpresponse ( not httpresponsemessage )
below code
public class logoutcontroller : apicontroller { [acceptverbs("get")] [system.web.http.route("logout/removecookie")] [system.web.http.httpget] public httpresponsemessage removecookie() { httpresponsemessage response = request.createresponse(httpstatuscode.ok); cookieheadervalue currentcookie = request.headers.getcookies("session-id").firstordefault(); if (currentcookie != null) { cookieheadervalue cookie = new cookieheadervalue("session-id", "") { expires = datetimeoffset.now.adddays(-1), domain = currentcookie.domain, path = currentcookie.path }; response.headers.addcookies(new cookieheadervalue[] { cookie }); } return response; } }
Comments
Post a Comment