Reputation: 124
I have to make web service in ASP.NET core and it should be accessible only from specific URL. No authentication with username and password.
I understand that I have to create some kind of custom filtering with middleware to achive this. But how do I get the callers URL address?
Upvotes: 0
Views: 2395
Reputation: 8642
In ConfigureServices you can use a CORS policy to only allow specific origins. (Change the IP address to be the IP or machine name that can call the service)
public void ConfigureServices(IServiceCollection services)
{
...
services.AddCors(action =>
{
action.AddPolicy("origin", policy =>
{
policy.WithOrigins(new string[] { "10.1.0.1" });
});
});
}
And then use it in Configure:
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
...
app.UseCors("origin");
...
}
Upvotes: 1