2012-09-18 3 views
0

인터넷 속도/대역폭에 따라 내용을 달리해야하는 웹 사이트를 개발하고 있습니다.asp.net에서 인터넷 속도 측정

대역폭이 낮은 곳에서는 웹 응용 프로그램이 일반 텍스트 만 표시하고 정상 대역폭의 경우 일반 웹 사이트가 표시됩니다.

나는 며칠이 지나서도 궁리 해왔다. 적절한 해결책을 찾지 못했다. asp.net에서 대역폭을 감지하는 간단한 방법이 있습니까?

감사

+0

[어떻게 서버에서 클라이언트의 다운로드 속도를 찾을 수 있습니까?]의 중복 가능성 (http://stackoverflow.com/questions/678635 클라이언트에서 서버로 다운로드 할 수있는 방법을 찾을 수있는 방법을 찾을 수 있습니다. –

답변

1

확인하기 위해 주어진 규정을 따르를 통해 확인 제공하는 대역폭에 대한 아이디어를 얻을 것이다 희망 당신의 인터넷 연결 속도 네임 스페이스 추가

using 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'.");    

    }