C# 共享主机和简单DoS攻击

C# 共享主机和简单DoS攻击,c#,shared-hosting,ddos,C#,Shared Hosting,Ddos,我的网站是在共享主机上托管的,如果您花费25%的CPU超过90秒,主机公司会自动禁用应用程序池。我想知道这段代码是否可以从简单的DoS攻击中卸载服务器 void Application_BeginRequest(object sender, EventArgs e) { HttpContext context = base.Context; string ip = context.Request.UserHostAddress; int activeRequests =

我的网站是在共享主机上托管的,如果您花费25%的CPU超过90秒,主机公司会自动禁用应用程序池。我想知道这段代码是否可以从简单的DoS攻击中卸载服务器

void Application_BeginRequest(object sender, EventArgs e)
{
    HttpContext context = base.Context;
    string ip = context.Request.UserHostAddress;

    int activeRequests = (int)(context.Cache[ip] ?? 0);

    activeRequests++;

    if (activeRequests == 1)
    {
        context.Cache.Add(ip, activeRequests, null, DateTime.Now.AddMinutes(10), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Normal, null);
    }

    if (activeRequests > 10)
    {
        log4net.Config.XmlConfigurator.Configure();
        log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        log.WarnFormat("Blocked IP: {0}, ActiveRequests: {1}", ip, activeRequests);

        Response.Clear();
        Response.Redirect("~/Error500.html");
    }
}

void Application_EndRequest(object sender, EventArgs e)
{
    HttpContext context = base.Context;
    string ip = context.Request.UserHostAddress;

    int activeRequests = (int)(context.Cache[ip] ?? 0);
    activeRequests--;
}
我所说的简单DoS攻击是什么意思

for (int i = 0; i < 100000; i++)
{
    WebClient client = new WebClient();
    client.DownloadString("http://example.com");
}
for(int i=0;i<100000;i++)
{
WebClient客户端=新的WebClient();
client.DownloadString(“http://example.com");
}
不,那代码没用。 此外,对于代理服务器后面的用户来说,这确实是一个问题:HTTP请求将由代理服务器发出,因此它后面的每台PC的客户端IP都是相同的

DoS预防是在应用程序代码之外的基础结构上进行的。 请参阅本文,作为有关IIS的示例:


因此,简而言之,DoS防护通常由主机提供商完成。

这是一种DoS攻击……谢谢,我更改了标题和问题中的缩写。代理背后的人是我网站流量的一小部分,我不担心他们。事实上,我无法访问IIS管理器-a来设置动态IP限制模块。一旦我的托管计划结束,我将转向更多面向.net的托管。我将开始新的机票,但我不相信我会成功。你已经面临拒绝服务攻击了吗?你真的确定你的主机提供商没有考虑到这种可能性吗(他们可以在基础设施的多个级别上工作,而不仅仅是在IIS上)?这真的很奇怪。。。在这种情况下,我唯一的建议是,正如您已经说过的,尽快更换提供商!:)