There is an attribute Referer
in the header
of Request
. If it is accessed from a browser, its value is empty. Use this to determine the subsequent processing procedure.
[HttpPost]
[ValidateAntiForgeryToken]
[Route("MainActionMethod")]
public async Task<IActionResult> MainActionMethod([FromBody]object jsonData)
{
if (true)
return RedirectToAction("Action1");
}
public IActionResult Action1()
{
StringValues header ;
Request.Headers.TryGetValue("Referer",out header);
if (header.Count==0)
{
return BadRequest();
}
return Ok("Action1");
}
CLICK HERE to find out more related problems solutions.