Atul Srivastava

Atul Srivastava

  • NA
  • 68
  • 744

XSRF Token not generating in Production Server using IIS 10

Jun 9 2019 10:41 AM
When running .Net Core Web API in local environment and Angular 5, XSRF token response cookies is getting generated but when deploy to production server, response cookies are not generated.
 
I have implemented CORS policy , web api and angular app are running in different domain and port and everything is working fine in dev  environment but when deploy to production environment response cookies are not getting created.
 
I am using below code in Startup.cs
  1. app.Use(async (context, next) =>  
  2. {  
  3. string path1 = context.Request.Path.Value;  
  4. if (path1 != null && path1.Contains("menu"))  
  5. {  
  6. ///// XSRF-TOKEN used by angular in the $http if provided  
  7. var tokens = antiforgery.GetAndStoreTokens(context);  
  8. context.Response.Cookies.Append("XSRF-TOKEN",  
  9. tokens.RequestToken, new CookieOptions()  
  10. {  
  11. Path = "/",  
  12. HttpOnly = false,  
  13. Expires = DateTime.Now.AddMonths(1),  
  14. }  
  15. );  
  16. }  
  17. await next();  
  18. });  
Please help me. Its urgent and not able to figure out what I am doing wrong.
I am running application using angular cli - ng serve and in production environment I am using IIS 10 and windows 2016 server.