0

I have a controller who gets a request.

I want to restrict it, so it is only locally.

I can't just restrict the web application to local access only, because it is only one particular method, that needs to be restricted.

How do i do that?

Thanks.

Matias Korn
  • 33
  • 1
  • 8

2 Answers2

1

How to limit page access only to localhost? one of the answers:

if (!HttpContext.Current.Request.IsLocal)
{ 
    Response.Status = "403 Forbidden";
    Response.End();
}

you might want to use Response.Redirect

Community
  • 1
  • 1
Robson
  • 916
  • 5
  • 22
0

Check UserHostAddress

if(Request.UserHostAddress != "127.0.0.1" && Request.UserHostAddress != "::1")
{
    throw new HttpException(403, "Forbidden.");
}
x2.
  • 9,554
  • 6
  • 41
  • 62