ASP.NET pages never stop loading - c#

We have a problem with many of our website written C# ASP.NET.
The problem is that often a C# page will never fully load from the server.
The page content itself load fine but Images but more annoying Scripts (Javascript) seam to hang and never come down and depending on the content it might lock up the page on Ajax Postback.
This problem is not limited to a single server as it happens on development machines as well as pre production and production servers.
The development machine are just using the inbuilt VS IIS Instance.
All pages that have this problem use ASP.NET Update Panels with varying versions of AJAX Toolkit.
Thanks

One of the possible reasons is that your postbacks are being triggered on some events which are either being fired continuously. Another possible cause is that the page life cycle is not getting completed (e.g. infinite loop). If you can post some code, you would get precise answers.
Thanks,
Vamyip

Try using asp.net trace to see which page event is taking longer. Also try using fiddler from client side to see the real traffic and error codes. If you share the fiddler logs I may be able to tell more about what's happening.

You can check the time used by all the resourced that are loaded on the page using Firefox and firebug add-on
Anyway the updatepanel doesn't work very well with heavy pages : it posts the whole page to the server and get the whole rendered HTML even if you need refresh a small portion of the page.
if you can you should replace the updatepanel with async Jquery call to the get the the response as JSON and then populate the page as you wish or try to use anothe approach similar to the update panel.
have a look at:
http://www.codeproject.com/KB/aspnet/partialRendering.aspx

Related

This browser does not support WebSockets [duplicate]

I'm trying to run an webpage inside a Webbrowser control wich contains a connection to an Websocket. The control can't connect to the Websocket.
When I tested in IE, everything runs ok, but in the Webbrowser control inside Visual Studio, the page can't connect to the Websocket.
I tried other pages that contains script to detect browser support for Websockets, when it runs in IE, the page show that Websocket runs with success, but when I'm try to run the same page on Webbrowser control, the page says that webcontrol can't run. How can I do to solve this problem?
Very thank you.
The problem is that the webbrowser control, while using the local IE as a basis, is more locked down (or maybe better to say "differently configured") by default.
The ability to control this is called Feature Control and you can read about it on MSDN here
In terms of solving your actual problems, a similar question has been solved with code provided in this answer to an equivalent question on C#. Note the tweaks in the subsequent answer as well.

Website scraper to the next level

So!
For a fansite I run I also run a website scraper(/xmleader) that reads information from a secure weblocation of a game. It works perfectly as it is now but I want to make it better and mainly faster.
The 1st problem I faced was how to maintain a session where you can do a ton of requests (like 1 to 10 every 30 seconds) while maintaining logged in. Normal httprequest didn't really worked because the login was secured with a token that must be submitted together with my login information. Now the solution was made as followed: On a Form is just placed a webbrowser control and when the login page was loaded(documentCompleted event) I fill the login information inside the document and simply submit it.
Now I can access all the secure pages I want to BUT not with a HttpWebRequest I placed inside the code. BUT When I placed multiple WebBrowserControls on the same form all them could access the secure part of the site. So that is how I placed 6 of them to do -kind of- parallel requests (for xml and html) to access information in my account quickly.
This works like a charm actually, you nicely see 7 browsers browse away and analyse the domdocument but naturally this creates a lot of overhead since I don't need the images and all the flash etc to load (or the iFrames which cause very annoying multiple documentLoaded events). So I want to login once and be able to request inside the code with HttpWebRequest with the session/cookie information of the webbrowser(or login in some other way).
So how do I do this? Is this even possible or should I approach it completely differently ?
(ps I write everything in C#)
You can show the first WebBrowser, login and, after the submit, you get the cookies from it and attach them all over your HttpWebRequests.
Having only the WebBrowser shown for the first login should improve your performance a lot!
Only pay attention to browser validation / async content loading.
You can't use HttpWebRequests to share the same session with WebBrowser. You'd need to use an API based on UrlMon or WinInet, that's what WebBrowser uses behind the scene.
I listed some of the options here: https://stackoverflow.com/a/22686805/1768303.
Perhaps, the XMLHTTPRequest COM object would be the most feasible one.

Update Windows Form Application UI from a Website [SCREEN-SCRAPING]

I have Windows Forms Application that Updates its GUI from a website using WebClient's GET Requests; However some of these values are updated in the web page using JavaScript so user don't have to keep refreshing the page to get them. How could i make my program get those values without having to keep sending new GET Requests.
The best way to do exactly what you want is to reverse engineer the javascript that updates the values on the page you're scraping. Beyond that, I'm afraid what you're doing is the best we can do.
On the plus side, javascript is nothing more than plain text source code so you can take a peek at it. But the legality of doing so depends on where you are. In most places including the US, just looking at the online code is legal. Reproducing it is not. But as the judge in the Oracle vs Google case said: it doesn't make sense to apply copyright to a single function (I'm paraphrasing, he said "range_check" not "a single function").
If the javascript is obfuscated then copy paste it into a pretty printer. Just Google for "javascript pretty printer". There are lots of them online.
You say that you want to be able to do something in C# like you do in JavaScript, but you don't want to have to "keep sending new GET Requests". The thing is, that's exactly what the JavaScript is doing. It just happens to be doing it asynchronously behind the scenes. You can do the very same thing with C#. The JavaScript is just doing GET or POST requests behind the scenes, and you can do the very same requests with C#.
Or you can simply set a timer to GetElementById from a hidden web browser

Why does my new .Net 4.0 EF application randomly lock up?

I have recently rolled out a new ASP .Net application. This application uses .Net 4.0 and the Entity Framework 4. It is a "basic" CRUD application. I almost exclusively used the EntityDataSource for Data Access.
The users have reported "ocassional freezing" of the application (they all use IE 8). If the user closes his browser and starts back up, the app is fine. It happens maybe once or twice per day total, usually to the heavy users. (So, I have been leaning toward memory leack or some other kind of resource limitation.)
Until just a little while ago, I have never seen this happen. It dosn't leave anything in the Event Log on the client PC nor Server. Also, there is nothing in the IIS error logs or the SQL logs.
A little while ago, I finally got it to happen. I was switching all of my EntityDataSources to use a single Object Context per page. I downloaded the EF Profiler (which seems to be a great product) and it pointed out that I am using multiple object contexts on many of my pages, due to the fact that many of them have more than one EntityDataSource. So, I was cleaning all this up and testing each page, when lo and behold....IE stopped loading pages!
At first, the page started loading slowly (and this was a page that I had already modified to use a single Object Context, so although I still believe I need to implement this "singleton" pattern throughout all my pages, I guess it isn't the culprit! Anyway..), then at some point I received:
Message: Sys.WebForms.PageRequestManagerTimeoutException: The server request timed out.
Still, nothing in the Event Log. I also checked the IIS web logs and I don't see anything, but they are pretty tough to read with the naked eye, I may have to download a parser to make sure there is nothing in there.
Anyway, I decided to start up another window and navigate to my app, and sure enough that window worked fine, no problems. I went back to the windows that stopped responding, refreshed it, waited... went to the home page of my app (which is basically just some static html.. and nothing.. ). Next, I opened a new tab in the window that is currently frozen and that tab works fine. So, I go back to the window that can no longer load pages from my app and try some other web sites.... espn.com loads fine, msn.com loads fine, I then enter the URL for my app home page (and tried some other pages in my app) and NOTHING. IIS doesn't even log the attempts in its Log Files (its like IE has just decided not to do anymore "gets" for my localhost!). Finally, after waiting for a while (while I was typing this post) I now have this error message in that window:
Internet Explorer cannot display the webpage. What you can try: The problem can be caused by a variety of issues, including: BLAH BLAH BLAH...
So, I jump back to that window and it can still browse Internet sites just fine. But, once again when I try to go to any of the pages in my app, I get NOTHING (spinning blue circle in the tab). So, once again I start a new tab in that same browser and I can browse around my application just fine.
What has my app done to this browser instance that will no longer let it load any of its pages (in fact, it seems like it isn't even doing a GET on any of the apps pages, since there is nothing new in the IIS logs...except for when I load the pages in these other tabs and/or browser windows that work fine, so the logging is still working...)? I will be forever indebted to the person that can help me figure this out. I am not sure it will do much good, but I am going to leave this browser window up on the chance that someone can tell me some things to try to diagnose this problem. It feel like I am THIS close to figuring it out. I finally have a window up that is misbehaving. I am afraid to close the window or do a new build on the app until I get some good input on things to try....
I should add that when this happened to me, I was running on my local PC, so I was the only user and only had one window open to the app..
Although, I am completely stumped!
We had the same issue and seemed to fix it by adding the following JavaScript to all pages with ajax:
window.onunload = abortRequest;
function abortRequest() {
Sys.WebForms.PageRequestManager.getInstance().abortPostBack();
}
I hope this helps!
sounds like a request just takes too long to execute. A web-browser is only allowed to keep two concurrent connections to a single webserver unless you utilize http pipelining (which isn't well supported anyway). However, My experience is that this is per browser, not per tab.
This is why nothing shows up in your logs, because your browser never initiate a request because it is waiting for the page to finish loading before it can fetch another page. I would start looking into the last request initiated before the lockup, it is probably that page that locks for some reason and never finishes.
ASP.NET utilizes only one thread as long as all request are sequential. As soon as you fire up two request simultaneously, a new thread is initiated (Init() on HttpApplication is invoked), and that can cause intermittent errors if you do funky stuff on Init().
If you think this is related to EF, you might read up on how to avoid locking in multi-threaded environment (because a web application is very much multi-threaded however this usually kicks in a production environment).
Ugh, I feel your pain - I hate these types of issues. Here's my divide-n-conquer process when something like this is happening (adapted somewhat to your case):
Step 1 - Environment Visibility
Get yourself set up so you can roughly see inside your systems. Set up Performance Monitor, and add a couple of important counters (IIS Current Requests, ASP.NET Current Requests, SQL Server - Active Transactions). The idea here with the "active requests/transactions" counters is you want to find out which part of the system is holding on to the request.
Additionally, add counters for total request time in IIS and the DB (so you can see it climbing as something is hanging on).
On your client PC, set up Fiddler.
Step 2 - Reproduce Issue
Usually at this point, the application realizes you can see it and starts behaving perfectly. ;) Stop and make sure you can still reproduce the issue.
Step 3 - Take the DB out of the equation
Create 4 pages in your application:
Static HTML file (.htm) that will NOT go through the ASP.NET runtime engine. This is your baseline for raw IIS.
ASPX page with no tricks (no database access, no processing, just a simple page that ASP.NET can spit out)
ASPX page with one simple database call (of some size, maybe do a single big query or something)
ASPX page with some complex transactions (multiple queries, etc)
Step 4 - Reproduce and measure
Since this issue will probably be pretty obvious once you can see it, find the bottleneck with your performance counters and Fiddler. Your issue sounds like you could have an intermittent connectivity issue (either between client and web server or web server/SQL), especially if IE is giving you the "page cannot be displayed" error, but you should see that in Fiddler. On the server side, you should see one of those performance counters hanging.
well, sounds like the app is waiting for a database operation to complete but is locked, probably because of another operation.
Try using the SQL profiler to trace the activity, and isolate what processes are running for a long time.
You can differentiate the requests using the SPID column in the trace view, it contains a unique ID number for each session from your App.
I have new information regarding this issue.
The application uses Integrated Authentication. This causes every reqest to come back (twice) with access denied, before IE send the credentials.
I can't help but wonder if this is what could be causing the "time outs".
I implemented an Ajax "Loading" animation on every page that prevents the user from clicking a button until the previous request is completed and that has GREATLY diminished the amount of "freezes" the users are experiencing.
Although, it still happens somewhat often.

JavaScript alerting from a C# class

I have a 5 ASPX page wizard.
Each one contains a SaveAndExit button that executes a C# function on a common static class. After saving, the C# code redirects to another page.
Is there a way for running javascript: alert('Data Saved'); after the saving, and before new page is Loaded.
You'll have to register a startup script on postback to do the alert. Then redirect via javascript after the alert.
You can't do it exactly like you want.
The C# code (server-side) can't run until the page has already posted back and unloaded from the browser. So by the time your server-side code is running the page doesn't even exist any more as far as the browser is concerned and it's too late to run your javascript code. This is true even in the middle of a post back, and even if the result of the post back will be the same page. That is why in certain circumstances ASP.Net pages can appear to flicker during post backs.
So you can't force a javascript alert after the data is saved without doing it via some kind of ajax call back-- and that's certainly one option. Another choice is to have the page to which you redirect show some kind of "data saved" message in certain circumstances; trigger it with something simple like a session variable or the value of hidden input on load so it's not obvious to the user.
But I think probably the best thing to do is nothing at all. It sounds like if the save fails you won't redirect. You'll probably even show some kind of error. If your user doesn't have enough confidence in your app that they don't trust it even when there's no error message and it's moved on to the next step, you're in trouble.
Vik, unless this is a homework I would highly suggest you don't.
JavaScript alert is very annoying to most users and seems completely useless in this case as explained by Joel Coehoorn.
If you insist on showing a message when it is saved then think of adding maybe a session variable and on the redirected page show the "Data saved" message at the top if the session variable exist and then delete the session variable.
Again though, as Joel Coehoorn said, you should definitely show a message if there is an error but redirecting should be all the "proof" they need that their data was saved.

Categories