is it possible to restrict an action method to only redirect-to access?

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.

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.

Leave a Comment

Your email address will not be published.

Scroll to Top