Hi @Ehsan ,
Is it possible to limit an action method which is not called from client browser? and is called from my web App always?
You only want to call that sendSMS
method/function from the code of other method(s) instead of exposing it as an action method, right?
In this scenario, you can apply the NonAction
attribute to the method, code as below:
public IActionResult Privacy()
{
//call the sendSMS method
var result = sendSMS("1001");
return View();
}
[NonAction]
public async Task<IActionResult> sendSMS(string mobileNumber)
{
// continued
return Ok("send SMS");
}
[Note] The NonAction
attribute indicates that a controller method is not an action method. After using this attribute, the send SMS
act as a normal method, and you can't use the RedirectToAction()
method to redirect to this method. And, if you call the action method from the client/browser (via the URL), it will show the 404 view page not found error.
In addition, you can consider creating a normal method instead of an action method, then call it from other action methods, code like this:
public IActionResult Privacy()
{
var result = sendSMS("1001");
return View();
}
public string sendSMS(string mobileNumber)
{
// continued
return "Success";
}
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best Regards,
Dillion