ASP.Net网页仅在局域网上可用

ASP.Net网页仅在局域网上可用,asp.net,iis-7,Asp.net,Iis 7,我有一个asp.net web应用程序,我希望人们只能从我的公司网络(LAN)使用它,我如何才能做到这一点???你可以 使用防火墙阻止结果连接!这是最安全的 使用登录页面,只允许注册用户 不太安全的方法是检查应用程序内部每个连接的IP 要检查IP,请在BeginRequest上读取客户端IP,检查其是否或您是否放置了您喜欢的其他IP,如果不是,请关闭连接: protected void Application_BeginRequest(Object sender, EventArgs e)

我有一个asp.net web应用程序,我希望人们只能从我的公司网络(LAN)使用它,我如何才能做到这一点???

你可以

  • 使用防火墙阻止结果连接!这是最安全的
  • 使用登录页面,只允许注册用户
  • 不太安全的方法是检查应用程序内部每个连接的IP
要检查IP,请在BeginRequest上读取客户端IP,检查其是否或您是否放置了您喜欢的其他IP,如果不是,请关闭连接:

protected void Application_BeginRequest(Object sender, EventArgs e)
{
    if(!IsPrivateNetwork(MyCurrentContent.Request.ServerVariables["REMOTE_ADDR"])
    {
        HttpContext.Current.Response.TrySkipIisCustomErrors = true;
        HttpContext.Current.Response.StatusCode = 403;
        HttpContext.Current.Response.End();
        return ;    
    }
}


public bool IsPrivateNetwork(string sMyIpString)
{
    long TheIpTranslate = AddressToNum(sMyIpString);

    if (TheIpTranslate >= 0)
    {
        // 192.168.0.0 192.168.255.255
        if (TheIpTranslate >= 3232235520 && TheIpTranslate <= 3232301055)
            return true;

        // 10.0.0.0 10.255.255.255
        if (TheIpTranslate >= 167772160 && TheIpTranslate <= 184549375)
            return true;

        // 172.16.0.0 172.31.255.255
        if (TheIpTranslate >= 2886729728 && TheIpTranslate <= 2887778303)
            return true;
    }

    return false;
}

public long AddressToNum(string cAddress)
{
    IPAddress MyIpToCheck = null;

    if (IPAddress.TryParse(cAddress, out MyIpToCheck))
    {
        return AddressToNum(MyIpToCheck);
    }
    else
    {
        return -1;
    }
}


public long AddressToNum(IPAddress Address)
{
    byte[] b = BitConverter.GetBytes(Address.Address);

    if (b.Length == 8)
        return (long)(((long)16777216 * b[0]) + ((long)(65536 * b[1])) + ((long)(256 * b[2])) + b[3]);
    else
        return 0;
}
受保护的无效应用程序\u BeginRequest(对象发送方,事件参数e)
{
如果(!isPrivateWork(MyCurrentContent.Request.ServerVariables[“REMOTE_ADDR”])
{
HttpContext.Current.Response.tryskipiiscustomerors=true;
HttpContext.Current.Response.StatusCode=403;
HttpContext.Current.Response.End();
返回;
}
}
公共图书馆工作(字符串sMyIpString)
{
long-TheIpTranslate=地址音调(sMyIpString);
如果(他们的翻译>=0)
{
// 192.168.0.0 192.168.255.255

如果(TheIpTranslate>=3232235520&&TheIpTranslate=167772160&&TheIpTranslate=28867229728&&TheIpTranslate大多数公司使用NAT盒,外部用户无法访问其内部网上的计算机。如果您在NAT后,请询问网络管理员