Mode:
Duration:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
using Microsoft.AspNetCore.Mvc;
public class DemoController : Controller
{
public IActionResult Info()
{
string method = HttpContext.Request.Method;
string path = HttpContext.Request.Path;
string user = HttpContext.User?.Identity?.Name ?? "Anonymous";
HttpContext.Response.Headers.Add("Custom-Header", "HelloWorld");
HttpContext.Session.SetString("Key", "SessionValue");
string sessionValue = HttpContext.Session.GetString("Key");
return Content($"Method: {method}\nPath: {path}\nUser: {user}\nSession: {sessionValue}");
}
}Coding works best on desktop or with an external keyboard.