|
Ok thanks, I'll move it to C# or Visual Studio Forums.
|
|
|
|
|
I'm hoping to cash in on the well-known ASP.Net expertise of CodeProject members. Currently I'm working on an ASP.Net website for a nonprofit organization with users in many developing countries, including locations where only dialup is available. The organization has determined that many of its users have disabled javascript for security reasons. The organization wants the new website to be graphically appealing, but also wants to be able to turn off most of the graphics for dialup users. This means we have to have some way of determining whether a request comes from a user on dialup or on broadband. The organization wants its home page to be filled with graphics for broadband users, which means there has to be a way to detect the connection speed in the background before sending a visible response to the browser.
At first I thought this wouldn't be possible from the server side. Although the advice I've found by searching many forums (including this one) suggested largely that this is the case, a few people thought it should be possible. Most of the suggestions involved timing downloads through WebClient or WebRequest/WebResponse. By running a number of tests on both dialup and broadband connections I've determined that the download method doesn't work because what's being timed is the length of time needed to send the download; without javascript there's no way to tell when it has actually been received by the browser.
A different approach was suggested via a PHP script posted by Emanuele Feronato on her blog[^]. This approach involves sending some text to the browser, one KB at a time, and flushing the response after each KB. She suggested sending 512 KB to get a good estimate of the connection speed, but that's far too much for dialup users to endure. I tested her approach with 16 KB and it seemed to give reasonable results. Since PHP is a server-side technology, I thought this might work in ASP.Net as well.
My C# code for the approach is below. The text I'm sending is just a collection of dots (ASCII 0x2e). To hide the text being pushed to the browser I've used a <span style="display:none;"></span> around it. Emmanuele used comment tags around the text to accomplish the same thing.
Here are a few things I've noticed:
1. The method doesn't work at all in ASP.Net unless you set Response.BufferOutput = true .
2. You have to flush the response buffer after each 1 KB or it doesn't work either.
3. Caching (or disabling caching) seems to have no effect on the results at all. I assume this is because the response is being buffered and flushed after each 1 KB.
4. For broadband connections (DSL at home and T1 at work, the latter shared with about 50 other users), I get estimated connection speeds of between 500 and 900 Kbps. This is well below the actual connection speeds for the two lines, but seems realistic in that it accounts for other things that are happening on the networks, plus transmission delays of one sort or another. Since I just want to distinguish broadband from dialup, the actual speed is not my primary interest.
5. For dialup connections the results are puzzling. On a series of tests with connections between 45.2 and 50.6 Kbps I've gotten some responses that seem reasonable (20-40 Kbps), but others that are far above what the connection should be able to support, sometimes going up to as much as 140 Kbps and in general averaging around 100 Kbps. This result is the same with Emmanuele's PHP script and with my translation of it into C#. I've determined that the results are not being served from the browser cache; everytime you hit F5 the results are different, sometimes with higher reported speeds and other times with lower speeds.
This procedure seems to permit me to distinguish between broadband and dialup users, but I'm uncomfortable with the results because of the discrepancies mentioned in point 5. I'd be grateful for any observations about what might be causing this. If I'm not timing the actual download, what am I timing instead?
Thanks for any observations or suggestions.
<<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
void Page_Load(object sender, System.EventArgs e)
{
Response.BufferOutput = true;
Response.ContentType = "text/HTML";
Response.Charset = "utf-8";
System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();
int nKB = 16;
string strK = "";
if (!String.IsNullOrEmpty(Request.QueryString["k"]))
{
strK = Request.QueryString["k"];
int nK;
if (Int32.TryParse(strK, out nK))
{
if ((nK > 0) && nK <= 25600) nKB = nK;
}
}
char[] charBuf = new char[1024];
for (int k = 0; k < 1024; ++k) { charBuf[k] = '.'; }
Response.Write("<span style=\"display:none;\">");
stopWatch.Start();
for (int i = 0; i < nKB; ++i)
{
Response.Write(charBuf, 0, 1024);
Response.Flush();
}
stopWatch.Stop();
Response.Write("</span>");
Response.Flush();
double dSpeed = (nKB * 8d) / stopWatch.Elapsed.TotalSeconds;
int nKbps = (int)dSpeed;
if (double.IsInfinity(dSpeed)) nKbps = -1;
string dOn = "<span style=\"color:Navy; font-weight:bold;\">";
string dOff = "</span>";
lblSpeed.Text = String.Format("Estimated connection speed using StopWatch = {0}{1:N0} Kbps{2},", dOn, nKbps, dOff);
lblKBytes.Text = String.Format("based on a download of {0}{1:N0} KBytes{2}.", dOn, nKB, dOff);
lblTime.Text = String.Format("Elapsed time using StopWatch = {0}{1} seconds{2}.", dOn,
stopWatch.Elapsed.TotalSeconds, dOff);
dOn = "<span style=\"color:Red; font-weight:bold;\">";
lblFreq.Text = String.Format("Stopwatch frequency on server = {0}{1:N0} ticks per second{2}.", dOn,
System.Diagnostics.Stopwatch.Frequency, dOff);
lblIsHR.Text = String.Format("Stopwatch using high-resolution timer on server? {0}{1}{2}.", dOn,
System.Diagnostics.Stopwatch.IsHighResolution, dOff);
if ((double)System.Diagnostics.Stopwatch.Frequency >= 1e9)
lblNano.Text= String.Format("Stopwatch on server is accurate to {0}less than one nanosecond{1}.", dOn, dOff);
else
lblNano.Text = String.Format("Stopwatch on server is accurate within {0}{1} nanoseconds{2}.", dOn,
((1000L * 1000L * 1000L) / System.Diagnostics.Stopwatch.Frequency), dOff);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Check connection speed in C#</title>
</head>
<body>
<form id="formPage" runat="server" style="font:normal 10pt Verdana;">
<div>
<asp:Label runat="server" ID="lblSpeed"></asp:Label><br />
<asp:Label runat="server" ID="lblKBytes"></asp:Label><br /><br />
<asp:Label runat="server" ID="lblTime"></asp:Label><br /><br />
<asp:Label runat="server" ID="lblFreq"></asp:Label><br />
<asp:Label runat="server" ID="lblIsHR"></asp:Label><br />
<asp:Label runat="server" ID="lblNano"></asp:Label><br />
</div>
</form>
</body>
</html>
|
|
|
|
|
Hey... Believe me .. this should be in your own blog post.
While reading each of the scenarios.. whatever solution that comes in mind is already tried by you. Really if you dont flush your buffered output, it doesnt goes to the browser and the browser instead of downloading, it actually waits for response.
Now if you are dealing with full postbacks, it is hard to use javascript. You might try partial postback using AJAX as well if possible to determine using Javascript. But I am really not sure if it can give you the exact download speed.
I think it is always better to have multiple ajax call (Just what gmail does) so that from the first call, it starts a timer in javascript (Say using SetInterval) and after a certain timeout for the timer, you show a message to switch to html view. This might be a good way of doing this.
|
|
|
|
|
Thank you for this reply. However, it doesn't really help because as noted in the original question I have to do the detection without javascript. AJAX won't be much help without javascript. But thanks anyway for the thought.
|
|
|
|
|
As I told you... The possible solutions that are there for you are already tried by you. No one can give you any other solution.. if I am right.
|
|
|
|
|
Hello,
I am working with AdRotator control in asp.net and sql server database.
In my homepage have 120 x 600 size.
Here i want to display diferent ads on every refresh as follows:
1)single 120 x 600 ad
2)two 12 x 300 ads
3)four 120 x 150 ads
How to display like this
please tell me
Thanks in advance
modified on Sunday, December 6, 2009 2:15 PM
|
|
|
|
|
Set the style width/ height to them.
But if you are using AdRotator you cant display two or more ads in one control. It comes one at a time.
So if you want to do this, create your own custom adrotator control which has this facility. Or you can use javascript to display more than one image as well..
|
|
|
|
|
Thanks for the reply
Can u please tell me the example.
|
|
|
|
|
|
|
public partial class admin_edit_sach : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
laysach();
}
}
private void laysach()
{
int masach = int.Parse(Request.QueryString["id"].ToString());
String StrCnn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Server.MapPath("~/App_Data/QLBansach.mdb");
OleDbConnection cnn = new OleDbConnection(StrCnn);
cnn.Open();
OleDbCommand cmd = cnn.CreateCommand();
cmd.CommandText = "select * from Sach where MaCD=" + masach;
OleDbDataAdapter da = new OleDbDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds);
txtTenSach.Text = ds.Tables[0].Rows[0]["Tensach"].ToString();
DropChuDe.SelectedValue = ds.Tables[0].Rows[0]["MaCD"].ToString();
DropNXB.SelectedValue = ds.Tables[0].Rows[0]["MaNXB"].ToString();
txtDonGia.Text = ds.Tables[0].Rows[0]["Dongia"].ToString();
Calendar1.SelectedDate = ds.Tables[0].Rows[0]["Ngaycapnhat"].ToString;
FileUpload1.FileName = ds.Tables[0].Rows[0]["Hinhminhhoa"].ToString();
txtMoTa.Text = ds.Tables[0].Rows[0]["Mota"].ToString();
cnn.Close();
}
protected void Btupdate_Click(object sender, EventArgs e)
{
int masach = int.Parse(Request.QueryString["id"].ToString());
String StrCnn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Server.MapPath("~/App_Data/QLBansach.mdb");
OleDbConnection cnn = new OleDbConnection(StrCnn);
cnn.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = cnn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "UPDATE Sach SET Tensach='" + txtTenSach.Text + "','" + DropChuDe.SelectedValue + "','" + DropNXB.SelectedValue + "','" + txtDonGia.Text + "','" + Calendar1.SelectedDate.Day + "/" + Calendar1.SelectedDate.Month + "/" + Calendar1.SelectedDate.Year + "','" + FileUpload1.FileName + "','" + txtMoTa.Text + "' Where MaNXB=" + masach;
cmd.ExecuteNonQuery();
cnn.Close();
Response.Redirect("~/Admin/ds_sach.aspx");
}
}
Erros
ompilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0428: Cannot convert method group 'GetType' to non-delegate type 'System.DateTime'. Did you intend to invoke the method?
Source Error:
Line 36: DropNXB.SelectedValue = ds.Tables[0].Rows[0]["MaNXB"].ToString();
Line 37: txtDonGia.Text = ds.Tables[0].Rows[0]["Dongia"].ToString();
Line 38: Calendar1.SelectedDate = ds.Tables[0].Rows[0]["Ngaycapnhat"].GetType;
Line 39: FileUpload1.FileName = ds.Tables[0].Rows[0]["Hinhminhhoa"].ToString();
Line 40: txtMoTa.Text = ds.Tables[0].Rows[0]["Mota"].ToString();
modified on Sunday, December 6, 2009 2:50 PM
|
|
|
|
|
Where is the parenthesis for this ??
Calendar1.SelectedDate = ds.Tables[0].Rows[0]["Ngaycapnhat"].ToString;
Should be
Calendar1.SelectedDate = DateTime.Parse(ds.Tables[0].Rows[0]["Ngaycapnhat"].ToString());
The parenthesis for ToString is missing ...
Cheers.
|
|
|
|
|
Try
Calendar1.SelectedDate =DateTime.Parse(ds.Tables[0].Rows[0]["Ngaycapnhat"].ToString());
|
|
|
|
|
Hi, I discovered Microsoft Chart Control a few days ago and have to say it's one of the greatest tool ever released . One that I found especially useful is the Dataformula.Financialformula function, which enables me to draw technical indicators on the chart.
However, is it possible to use the financialformula to return data as an array/arraylist?
I want to be able to put these technical data outputs into a database. So far I could only get the funciton to return output in a series, and I don't know how to convert the data in a series into an array/arraylist/datatable.
I'd greatly appreciate if anyone could help me out. Thanks!!
|
|
|
|
|
I have one quite simple website made by ASP.net, visual studio 2005, the website is nothing but just display 'hi'.
I just want to know how to us IIS for it. however, it gives the following error message:
This configuration section can not be used in this path. This is the case when the section is locked at a higher level. The closure takes place by default (overrideModeDefault = "Deny") is explicitly or with a location tag with overrideMode = "Deny" or the Legacyeinstellung allowOverride = "false" set.
anyone can tell me what is the problem? thanks!!
I have translated from German, the original information is as follows:
HTTP-Fehler 500.19 - Internal Server Error
Auf die angeforderte Seite kann nicht zugegriffen werden, da die zugehörigen Konfigurationsdaten für die Seite ungültig sind. Ausführliche Fehlerinformationen
Modul IIS Web Core
Benachrichtigung BeginRequest
Handler Noch unbestimmt
Fehlercode 0x80070021
Konfigurationsfehler Dieser Konfigurationsabschnitt kann in diesem Pfad nicht verwendet werden. Dies ist der Fall, wenn der Abschnitt auf übergeordneter Ebene gesperrt ist. Die Sperrung erfolgt standardmäßig (overrideModeDefault="Deny") oder wird explizit mit einem location-Tag mit overrideMode="Deny" oder der Legacyeinstellung allowOverride="false" festgelegt.
Konfigurationsdatei \\?\D:\publish_webtest\web.config
Angeforderte URL http://192.168.2.100:8080/
Physikalischer Pfad D:\publish_webtest
Anmeldemethode Noch unbestimmt
Angemeldeter Benutzer Noch unbestimmt
Konfigurationsquelle
97: </modules>
98: <handlers>
99: <remove name="WebServiceHandlerFactory-Integrated"/>
|
|
|
|
|
How did you hosted your site on IIS ? Did you create virtual directory properly ? Where is your web.config file located ?
Seraph_summer wrote: I have one quite simple website made by ASP.net, visual studio 2005, the website is nothing but just display 'hi'.
I just want to know how to us IIS for it.
1. Create Web site using Visual Studio.
Note : During creation of web site if you select File Location as HTTP, then it will also create the Virtual Directory at IIS.
2. After creation of Web site just published the site.
3. Goto Published folder. Then you can use Folder Web sharing option for create the virtual Directory or Open IIS manager to to create Virtaul Directory.
Here is one of my beginners article on IIS. It may help you to move ahead.
Beginner's Guide : Exploring IIS 6.0 With ASP.NET [^]
Let me know if you have any further issue.
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
HI,
thank you very much!
I just repeat exactly as what you have introduced in your article "Deploying ASP.NET Websites on IIS 7.0"
, the same error gives, that is to say, the web.config has problem, I can not understand at all. because I just create a
default website based on ASP.net without doing anything.
frankly speaking, my website has been ready several months ago, I just want to publish it, but I do not how to publish it.
I really have no idea why it is not succeful. Could you please help me? what could be the reason?
I really hate IIS.
I am looking forward to your reply.
thanks again.
|
|
|
|
|
Hi, again me,
I found one potential prolem
to check the authorize, it displays the folloiwng informaitn,
"The server is configured to be used to access the specified physical path pass-through authentication with a predefined account. IIS Manager can not verify whether the built-in account has access. Make sure that the application pool identity has Read access to the physical path. If the server is connected to a domain, and the identity of the application pool "Network Service" or "Local System" is to make sure that has <domain> \ $ <computername> read access to the physical path. Try these settings again."
Do you think is this cause the problem? if so, then what does it mean exactly?
|
|
|
|
|
Hi guys.. Actually i have an web application running on vs2003 it fetches the records from a list of xml file now i want to import all my data that is present in the xml file to sql db(sybase).. can any one guide me as to how can i import the data using c# coding...
Thanks in advance...
|
|
|
|
|
Loop through the records and insert one by one to database.
Best wishes,
Navaneeth
|
|
|
|
|
Im a fresher actually.. i do accept ur idea.. hav u got any tutorials or samples... i googled alot dint get the apt one...
I tried using Sqlbulkcopy but that doesnt work with vs2003... and also there are duplicate rows in my xml files...
thanx in advance...
|
|
|
|
|
Ok. To read records from XML, use the classes provided in System.Xml name space. Work with XmlDocument[^] and load the XML to it. XmlDocument class provides methods to get collection of nodes. Start a loop that iterates over the collection.
To insert data into SQL database, you need to prepare insert SQL statement with necessary parameters. Then work with SqlConnection , SqlCommand classes. Execute the DB statement in each iteration of the loop. If you want to avoid duplicate records, create a primary key on the database table and when you try to insert duplicate records, SQL server will throw exception. Handle this and proceed to next row.
All the classes which I explained has got very neat documentation and you should be able to start easily.
<<thashif>> wrote: Im a fresher actually
<<thashif>> wrote: i googled alot dint get the apt one..
While searching on the Internet is good, as a fresher you should be learning stuff initially from a book. Not all the stuff in Internet are correct and reading from a book makes real difference. So I suggest you to get a good book on the subject and start working with the examples rather than wasting time on online forums or doing search.
Best wishes,
Navaneeth
|
|
|
|
|
When internet explorer opens my dotnet code should identify that. How can we do that? Please help me with this.
|
|
|
|
|
srikantha_nagaraj wrote: When internet explorer opens my dotnet code should identify that.
When you post questions you should identify correct forum.
srikantha_nagaraj wrote: Please help me with this.
Your question is terribly unclear and off topic to this forum. If your question has anything to do with ASP.NET, explain it clearly. If not, move to correct forum.
Best wishes,
Navaneeth
|
|
|
|
|
No way... If you are talking about process in the client side, it cant detect it from the browser.. As browser only deals with htmls(Request / Response). It dont have access to anything, but just to display some Data and Ui elements.
If you are looking for server side processes, it is very easier to deal with this. Just use
System.Diagnostics.Process[] processlist = System.Diagnostics.Process.GetProcesses()
But I dont think your motive is fulfilled using this as no one opens internet explorer to work with their own site in the server.
Anyway.. Be specific on what you require always. And post in right section.
Cheers.
|
|
|
|
|