Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created October 5, 2015 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjoerntx/ae044f91e46fec6f2308 to your computer and use it in GitHub Desktop.
Save bjoerntx/ae044f91e46fec6f2308 to your computer and use it in GitHub Desktop.
Uri uri = new Uri("http://" +
Request.Url.Authority + "/Home/SaveTemplate");
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
// get the AuthCookie
var authCookie =
FormsAuthentication.GetAuthCookie(User.Identity.Name, true);
// create a new Cookie
Cookie requestAuthCoockie = new Cookie()
{
Expires = authCookie.Expires,
Name = authCookie.Name,
Path = authCookie.Path,
Secure = authCookie.Secure,
Value = authCookie.Value,
Domain = uri.Host,
HttpOnly = authCookie.HttpOnly,
};
// add the AuthCookie to the WebRequest
request.CookieContainer = new CookieContainer();
request.CookieContainer.Add(requestAuthCoockie);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment