C# ASP.net Test if user comes from Local Network

落花浮王杯 提交于 2019-12-10 19:52:54

问题


I want to use C#/ASP.net to find out whether the user browsing the website is on the same network so that certain links are only displayed while in the office (to those who have access to them).

Anyone accessing from within the office will be doing so by going to it's local IP address (i.e. 192.168.x.x) whereas external users will be browsing to the public domain name.

All I need is some way to differentiate between the two types of user.


回答1:


if (Request.UserHostAddress.StartsWith("192.168"))
{
    //localuser
}



回答2:


Take a look @ Request.Url.Host - you'll be able to pluck the address from this.



来源:https://stackoverflow.com/questions/3250567/c-sharp-asp-net-test-if-user-comes-from-local-network

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!