How to open URL in memory

A

Alex Sinclair

Hi,

I'm having a problem with what should be a simple task: in ASPX, how can I
open a page while I'm at another page, without going to that page in the
browser, only programmatically.

So for example, I'm on page one.aspx, user types www.microsoft.com in a
textbox and clicks a button, the C# code behind needs to go and grab the
microsoft page and get the source back, modify it, and then display it to
the user. One can get a stream written back with the Server.Execute method,
but that only works on aspx pages. Is there a way to read any page this
way, I seem to recall that ASP had this capability before.

Thanks for your help,

Alex
 
H

Hermit Dave

Try WebClient. Think that's what you are looking for.

HTH

Dave

nntp://msnews.microsoft.com/microsoft.public.dotnet.framework.aspnet/<gyf3c.13130$506.9722@fed1read05>

Hi,

I'm having a problem with what should be a simple task: in ASPX, how can I
open a page while I'm at another page, without going to that page in the
browser, only programmatically.

So for example, I'm on page one.aspx, user types www.microsoft.com in a
textbox and clicks a button, the C# code behind needs to go and grab the
microsoft page and get the source back, modify it, and then display it to
the user. One can get a stream written back with the Server.Execute method,
but that only works on aspx pages. Is there a way to read any page this
way, I seem to recall that ASP had this capability before.

Thanks for your help,

Alex




[microsoft.public.dotnet.framework.aspnet]
 
S

SStory

Hi,

I think this will help you.
I get the page, entire HTML in memory as follows:

Private Function GetPageAsString(ByVal strCallingPageURL As String) As
String
Dim CallingPageURI As New Uri(strCallingPageURL)
Dim rq As WebRequest = WebRequest.Create(CallingPageURI)
Dim wr As HttpWebResponse = rq.GetResponse
Dim inStream As Stream = wr.GetResponseStream
Dim reader As New StreamReader(inStream)
Dim data As String = reader.ReadToEnd
reader.Close()
inStream.Close()
GetPageAsString = data
End Function

HTH

Be aware that if you use HTTP_REFERER to get the calling pages URL--it is
sometimes blank and can be a pain if this is what you want to do.

Shane

Hermit Dave said:
Try WebClient. Think that's what you are looking for.

HTH

Dave
nntp://msnews.microsoft.com/microsoft.public.dotnet.framework.aspnet/ said:
Hi,

I'm having a problem with what should be a simple task: in ASPX, how can I
open a page while I'm at another page, without going to that page in the
browser, only programmatically.

So for example, I'm on page one.aspx, user types www.microsoft.com in a
textbox and clicks a button, the C# code behind needs to go and grab the
microsoft page and get the source back, modify it, and then display it to
the user. One can get a stream written back with the Server.Execute method,
but that only works on aspx pages. Is there a way to read any page this
way, I seem to recall that ASP had this capability before.

Thanks for your help,

Alex




[microsoft.public.dotnet.framework.aspnet]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top