【问题标题】:Measuring internet speed in asp.net在asp.net中测量互联网速度
【发布时间】:2012-09-18 06:15:50
【问题描述】:

我正在开发一个需要根据互联网速度/带宽改变内容的网站。

在带宽较低的地方,Web 应用程序应该只显示 纯文本和正常带宽显示正常网站。

几天以来我一直在考虑它,但我无法找到合适的解决方案。 有没有一种简单的方法来检测asp.net中的带宽?

谢谢

【问题讨论】:

标签: asp.net bandwidth


【解决方案1】:

按照给定的代码检查您的互联网连接速度 添加命名空间

使用 System.Net;

在测试按钮点击事件上编写代码..

  Uri URL = new Uri("http://sixhoej.net/speedtest/1024kb.txt");

    WebClient wc = new WebClient();

    double starttime = Environment.TickCount;


    // download file from the specified URL, and save it to C:\speedtest.txt

    wc.DownloadFile(URL, @"C:\speedtest.txt");


    // get current tickcount

    double endtime = Environment.TickCount;


    // how many seconds did it take?

    // we are calculating this by subtracting starttime from endtime

    // and dividing by 1000 (since the tickcount is in miliseconds.. 1000 ms = 1 sec)

    double secs = Math.Floor(endtime - starttime) / 1000;


    // round the number of secs and remove the decimal point

    double secs2 = Math.Round(secs, 0);





    // calculate download rate in kb per sec.

    // this is done by dividing 1024 by the number of seconds it

    // took to download the file (1024 bytes = 1 kilobyte)

    double kbsec = Math.Round(1024 / secs);

    Label1.Text = "Download rate: " + kbsec + " kb/sec";

    try

    {

        // delete downloaded file

        System.IO.File.Delete(@"C:\speedtest.txt");

         Response.Write("Done.");

    }

    catch

    {

        Response.Write("Couldn't delete download file.");

         Response.Write("To delete the file yourself, go to your C-drive and look for the file 'speedtest.txt'.");            

    }     

【讨论】:

    【解决方案2】:

    请检查以下链接,希望您能了解有关带宽检查服务请求的想法

    1. Stack Answer
    2. Stack Answer

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-28
      • 1970-01-01
      • 1970-01-01
      • 2022-11-19
      • 2017-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多