In ASP.NET Core how do you check if request is local?

前端 未结 6 833
粉色の甜心
粉色の甜心 2020-12-15 03:15

In the regular ASP.NET you could do this in a view to determine if the current request was from localhost:

HttpContext.Current.Request.IsLocal

B

6条回答
  •  春和景丽
    2020-12-15 03:57

    now its

    HttpContext.Connection.IsLocal
    

    and if you need to check that outside of a controller then you take a dependency on IHttpContextAccessor to get access to it.

    Update based on comment:

    HttpContext is intrinsically available in Views

    @if (Context.Connection.IsLocal)
    {
    
    }
    

提交回复
热议问题