473,671 Members | 2,171 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASP.NET - Set WebStream to Timeout

32 New Member
Hello,

I currently have a routine that copies the contents of a web request into a string. I would like, however, to set the period after which the reader will throw an exception. I don't want my users to wait 300 seconds, instead I would rather have an exception thrown and the user notified of the service essentially being down. Here is what I've come up with, but it doesn't seem to timeout correctly. Any suggestions?

Assume any variables starting with _ are class level and have been configured properly. The _RequestTimeout variable is set to 1.

Expand|Select|Wrap|Line Numbers
  1.     Private Function GetWebPage(ByVal URL As String) As String
  2.         Dim Response As String = String.Empty
  3.         Dim WebReader As StreamReader
  4.         Dim WebStream As Stream
  5.  
  6.         Try
  7.             '-- Download and read web page
  8.             WebStream = _Request.OpenRead(URL)
  9.  
  10.             '-- Set timeout on read for the default of 10 seconds or a user specified amount
  11.             WebStream.ReadTimeout = Me._RequestTimeout
  12.  
  13.             '-- Read web stream
  14.             WebReader = New StreamReader(WebStream)
  15.             Response = WebReader.ReadToEnd()
  16.  
  17.         Catch ex As Exception
  18.             Throw New Exception(ex.Message)
  19.         Finally
  20.             '-- Release memory
  21.             WebReader = Nothing
  22.         End Try
  23.  
  24.  
  25.         Return Response
  26. End Function
Nov 13 '07 #1
5 1607
Plater
7,872 Recognized Expert Expert
So you want it to keep reading until it finishes or X amount of seconds has ellapsed, whatever comes first?
Nov 13 '07 #2
poe
32 New Member
Correct.

I have an aspx page that is called via Ajax from an old asp page as a part of the form submission for the asp page; the Ajax portion is not 100% necessary, so if it takes too long to complete, I just want to skip over it. My users have complained that "it doesn't do anything" but they're just not willing to wait long enough, so I have to work around it.
Nov 13 '07 #3
Plater
7,872 Recognized Expert Expert
Well I think Response.End() forces the page to stop executing code?
So do a check to see if X amount of seconds has passed and then kill off the page?
Nov 13 '07 #4
poe
32 New Member
Just to update. I was able to change from using the WebRequest to using an HttpWebRequest. New in .Net 2.0 is the Timeout member which allows you to specify an amount of time after which an exception is thrown. The neat thing it that HttpWebRequest inherits from WebRequest so the change was minimal.
Nov 15 '07 #5
Plater
7,872 Recognized Expert Expert
I had been wondering why you weren't using those, but figured I didn't understand the scope of your application.
Nov 15 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

9
2618
by: E Sullivan | last post by:
I am having a time out issue when multiple users are accessing the server. This time out does not happen all of the time. My understanding is that the time out value is actually set in two places. I believe one is in the asp pages for the session itself, and the other is more of a system timeout settting in IIS. Would one of these supercede the other if the two are different? I have already looked at the time out setting in IIS, and it...
12
43189
by: Geigho | last post by:
Setting session timeout in web.config file does not seem to have any effect. Any explanation or suggestion will be appreciated.
2
862
by: Greg Decos | last post by:
I am using forms authentication using a FormsAuthenticationTickets set to expire in 30 minutes and the ticket is added to the collection of cookies. I am not sure where the following values are used: 1. timeout in: <authentication mode="Forms"> <forms ...timeout="30" 2. session timeout defined in IIS 3. timeout in
4
15460
by: DavidS | last post by:
First: There are several ways to confuse one regarding session timeout. (1) web.config - <sessionState timeout="20"> (2) IIS Manager | Internet Information Services | ServerNode | Default Web Site | Properties | Configuration | Options | Enable Session State Session timeout 20 (3) within Global.asax.vb file - Session_Start subroutine can use Session.Timeout=x minutes or (4) within any web page, i.e., <web page>.aspx can use...
4
9436
by: UJ | last post by:
I have a page where the user can upload a video file. As you can guess, this may take a while. Is there a way I can change the session timeout for just this one page? I would also want to change the forms authentication to be a large value for that page also. TIA - Jeff.
22
5279
by: Nick Craig-Wood | last post by:
Did anyone write a contextmanager implementing a timeout for python2.5? I'd love to be able to write something like with timeout(5.0) as exceeded: some_long_running_stuff() if exceeded: print "Oops - took too long!"
25
6074
by: =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?= | last post by:
I tried: <sessionState timeout="1"> </sessionState> bounced IIS, and after 1 minute still had a session. ??? -- thanks - dave
5
3773
by: Masso | last post by:
Hallo to the group, my question is this: where i have to set timeout in a web application? If i set into sessionState with property Timeout="60", after 20 minutes the session is over. Always after 20 minutes, i cannot set a timeout greater than 20 minutes. Our configuration is the following: - Server with Win2003, i.e. IIS 6.0 - Web application developed with vb.net simply composed by:
2
6435
by: JimLad | last post by:
Hi, I've got a very basic asp.net page that accesses a very slow db query and siplays to screen. I'm hitting a timeout aftre about 3.5 to 4.5 minutes - seems to be variable. SQL connection string timeout is set to 3000s. SQL Command timeout is set to 3000s. IIS Connection Timeout is set to 120s. ASP.NET script timeout is not set so must use default of 90s.
0
8476
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8393
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8914
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8820
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8598
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7433
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6223
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5695
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.