Created
November 21, 2016 17:11
-
-
Save DaniJG/ac1e54579985efe96718fc70b0f1a069 to your computer and use it in GitHub Desktop.
ASP.Net Core 1.1 test setting cookie in controller action
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Just run in the browser console: | |
$.ajax({ | |
url: '/api/fetch', | |
method: 'POST', | |
data: JSON.stringify({foo: 'bar'}), | |
contentType: 'application/json' | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.AspNetCore.Mvc; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Threading.Tasks; | |
namespace TestApplication.Controllers | |
{ | |
[Route("api/[controller]")] | |
public class FetchController : Controller | |
{ | |
[HttpPost] | |
public JsonResult Post([FromBody]object loginParam) | |
{ | |
System.Diagnostics.Debug.WriteLine(Request.Cookies["id2"]); | |
Response.Cookies.Append("id2", "8"); | |
return Json(null); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"dependencies": { | |
"Microsoft.NETCore.App": { | |
"version": "1.1.0", | |
"type": "platform" | |
}, | |
"BundlerMinifier.Core": "2.2.306", | |
"Microsoft.AspNetCore.Diagnostics": "1.1.0", | |
"Microsoft.AspNetCore.Mvc": "1.1.0", | |
"Microsoft.AspNetCore.Razor.Tools": "1.1.0-preview4-final", | |
"Microsoft.AspNetCore.Routing": "1.1.0", | |
"Microsoft.AspNetCore.Server.IISIntegration": "1.1.0", | |
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.1.0-preview4-final", | |
"Microsoft.AspNetCore.Server.Kestrel": "1.1.0", | |
"Microsoft.AspNetCore.StaticFiles": "1.1.0", | |
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.0", | |
"Microsoft.Extensions.Configuration.Json": "1.1.0", | |
"Microsoft.Extensions.Logging": "1.1.0", | |
"Microsoft.Extensions.Logging.Console": "1.1.0", | |
"Microsoft.Extensions.Logging.Debug": "1.1.0", | |
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.0", | |
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.1.0" | |
}, | |
"tools": { | |
}, | |
"frameworks": { | |
"netcoreapp1.1": { | |
"imports": [ | |
"dotnet5.6", | |
"portable-net45+win8" | |
] | |
} | |
}, | |
"buildOptions": { | |
"emitEntryPoint": true, | |
"preserveCompilationContext": true | |
}, | |
"runtimeOptions": { | |
"configProperties": { | |
"System.GC.Server": true | |
} | |
}, | |
"publishOptions": { | |
"include": [ | |
"wwwroot", | |
"**/*.cshtml", | |
"appsettings.json", | |
"web.config" | |
] | |
}, | |
"scripts": { | |
"prepublish": [ "bower install", "dotnet bundle" ], | |
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment