【问题标题】:Allow specific users to access application on hosting允许特定用户访问主机上的应用程序
【发布时间】:2011-09-12 09:22:19
【问题描述】:

我要在主机上发布我的应用程序,我已经决定要购买哪个主机。我希望能够拒绝任何人从网络上查看该应用程序,除了一些将接受测试的人。

我不确定托管通常是否允许做一些类似的事情,为应用程序设置一些选项或任何 IP 地址限制。我知道可以在 IIS 中进行操作,但不确定托管是否允许直接访问 IIS。否则我需要在我的应用程序中实现它。

您对此有何经验?

我的应用基于 asp.net mvc 3.0 构建。

托管我选择 arvixe.com(尚未购买)。我在电子邮件中问了他们这个问题,但还没有得到任何答复

【问题讨论】:

    标签: asp.net asp.net-mvc asp.net-mvc-3


    【解决方案1】:

    正如您已经指出的那样,使用 IIS 限制/允许特定 IP 地址非常容易。但是根据您的情况,您的提供商可能不会授予您调整此部分的权限。

    您可以做的是创建一个HttpModule并通过这种方式限制IP地址。这是这个实现的一个很好的例子:

    http://www.codeproject.com/KB/aspnet/http-module-ip-security.aspx

    这里是代码:

    /// <summary>
    /// HTTP module to restrict access by IP address
    /// </summary>
    
    public class SecurityHttpModule : IHttpModule
    {
     public SecurityHttpModule() { }
    
        public void Init(HttpApplication context)
        {
            context.BeginRequest += new EventHandler(Application_BeginRequest);
        }
    
        private void Application_BeginRequest(object source, EventArgs e)
        {
            HttpContext context = ((HttpApplication)source).Context;
            string ipAddress = context.Request.UserHostAddress;
            if (!IsValidIpAddress(ipAddress))
            {
                context.Response.StatusCode = 403;  // (Forbidden)
    
            }
        }
    
        private bool IsValidIpAddress(string ipAddress)
        {
            return (ipAddress == "127.0.0.1");
        }
    
        public void Dispose() { /* clean up */ }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-16
      • 1970-01-01
      • 2019-05-06
      • 2012-04-16
      相关资源
      最近更新 更多