I am building an mvc application and I am making an api controller to allow ajax requests from some of my front end pages. I want to restrict the api controller actions to only allow requests from my server (so people can not call my api from their own sites).
After some searching around, I found numerous solutions proposing a custom authorize attribute, which I made:
public class LocalRequestOnlyAttribute : AuthorizeAttribute
{
protected override bool AuthorizeCore(HttpContextBase context)
{
return context.Request.IsLocal;
}
}
and then dropped it on my controller action with [LocalRequestOnly]
it works fine on localhost, but on my aws server, it does not work, the ajax request comes back as an error
EDIT - Details:
I am using the hostname with a relative path. so my url for the ajax call is "/api/getdata".
I am not setting any ajax request headers.
The error I am getting back is No 'Access-Control-Allow-Origin' header is present on the requested resource.