简体   繁体   中英

ASP.NET Method local access only

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.

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

Check UserHostAddress

if(Request.UserHostAddress != "127.0.0.1" && Request.UserHostAddress != "::1")
{
    throw new HttpException(403, "Forbidden.");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM