Firing Click events and Reading IFrame Source of External URL in ASP.NET web form

G

Guest

Hi

I have developed a Windows Application(C# Windows Form) which will get the IFrame Source of the page it is navigating using Webbrowser Control. Now I want do this in ASP.Net web application(C# Web Form).

Is there any other method through which I will be able to access the IFrame Source of the page I am navigating to. Also I need to click on some of the links in the page I am navigating. Requirement is to read the data the IFrame source is contains.

I tried using Webbrowser Control in ASP.Net Web Form but once the Webbrowser Control is placed on Web Form, if the application is run, getting Page cannot be displayed error. Also tried calling Windows Application (.exe) which is already developed in ASP.Net web form, that is also not working

Please anybody can help me how to read the IFrame Source and Fire Click events of page it is navigating through in ASP.Net. From our portal we need to navigate to external URL. Once it is navigated to externalURL, I have to fire some click events and read the IFrame source.

Regards
E
 
S

Steven Cheng[MSFT]

HI Ej,

From your description, you used to use WebBrowser Control in your winform
app and navigate some pages from external sites and do some operations on
the retrieved page's dom collection, also programmatically fire some events
on those page. And now you'd like to move such function in an asp.net web
page. You use the iframe element to contain the external page and wonder
how to control the page in the iframe , yes?

As for this problem, here are my suggestions:
1. In web page, we generally can use javascript to manipulate the iframe
element embeded in a certain web page. For example, change its url , get
its frame or docuemnt object and loop through its html elements collecton.
However, this has the limitation that we can only do such operations on a
page which is from the same domain of the container page(where the iframe
is in ). For example our web app's in the www.mydomain.com and one page
contains the iframe. if the iframe's containing page is also from the same
domain , such as a.mydomain.com or b.mydomain.com, it'll be ok for us to
use javascript to requry the dom collection of the iframe page, otherwise,
we'll be unable to do so(will encounter permission denied error). Here are
some related tech articles:

http://www.codeproject.com/jscript/slite.asp

http://www.oreillynet.com/pub/a/javascript/2002/02/08/iframe.html

2. If you do want to implement the same functions as your winform app, I
think you can create a Winform control which wrapper the WebBrowser control
and also encapsualte all those functions(such as get the navigated page's
source and fire some events on it). And then, embeded the winform control
in your web page. This is called IE hosted winform control. But that'll
need the clientside to grant enought permissions to run the rich client
control in IE. Below are some referene on IE host winform control:

http://samples.gotdotnet.com/quickstart/winforms/doc/WinFormsIeSourcing.aspx

#Simple way to expose a .NET WinForm control as an ActiveX control in any
HTML page
http://www.codeproject.com/cs/miscctrl/htmlwincontrol.asp

Hope helps. Thanks..

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
G

Guest

Yes, your undestanding of question is right.

I tried the sample from codeproject and it works only if the usercontrol file is placed within the application folder, if it is placed in bin folder, on click of Button, undefined message is displayed

Now I tried placing Webbrowser Control similar way onto the Webform, but nothing is happening. No mesage os also getting displayed. What can be the reason

Is there any other approach is there to read the external URL source through ASP.Net Webfrom

Thanks
EJ
 
G

Guest

HI Steven

When a usercontrol is created placing a AxWebbrowser Control in it and placed this usercontrol inside webform and executed the control itself is not getting displayed. If any other controls are placed in user control and tried there is no problem everything works fine.

What is the solution for this? Or Is there any other way to read source code of external URL we are navigating to

Please help us.

Thanks
Vani
 
G

Guest

HI All

Please anybody give us the solution. There are no replies coming for this question. Time is running out, please help us

Thanks
EJ
 
S

Steven Cheng[MSFT]

Hi Vani

I'm sorry to hear that the Embeded WebBrowser in a asp.net UserControl
bings new troubles. In fact I also suspect whether this is an appropriate
approach. Since you mentiond that get the response's html source of the
remote url. The "HttpWebRequest" class come to my mind, it can help post
request to a certain web url address and retrieve back the httpResponse
from it. The response is returned as an HttpWebResponse class's instance
and we can get the response html source from the Stream it contained. But
if you want to manipulcate the source as a DOM collection, we still need to
manually parse it. Here are some certain web resources on using the
HttpWebRequest:

#HttpWebRequest.GetResponse Method
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemNetHttpWebRequ
estClassGetResponseTopic.asp?frame=true

#How to use HttpWebRequest to send POST request to another web server
http://www.netomatix.com/HttpPostData.aspx

#Crawl Web Sites and Catalog Info to Any Data Store with ADO.NET and Visual
Basic .NET
http://msdn.microsoft.com/msdnmag/issues/02/10/SpiderinNET/default.aspx
http://blogs.toneengel.com/btone/archive/2002/09/22/192.aspx

Hope helps. Also, please feel free to post here if there are anything else
we can help. Thanks.


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
G

Guest

Thanks for the reply.

We can not use webrequest and webresponse since we need to show the Remote URL to Users and they need to login to the Remote URL. Once they login to remote URL our application has to do click on some links before reading required data from the Iframe Source.

So is there any other way out to do this? please help us...,

Thanks,
EJ
 
G

Guest

HI Steven

Thanks for in depth research. We will try the same and get back to you

I am unable to see the attached code of the test Winform Control which you have tried. Can you repost the same

Thanks
EJ
 
S

Steven Cheng[MSFT]

Hi EJ,

The attachment in the thread is visible when you are using the OE the view
the thread, if you are visiting the thread via
web client, I'm afraid you can't see the attachment. So please make sure
you're using OE client. Also, if you feel convenient, you can provide the
mail address so that I can attach it via mail. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
G

Guest

HI Steven

You can send the sample code to above ID

Also the sample code for using it ASP.Net webform

Thanks
E
 
G

Guest

HI Steven

Still I have not received the reply from you. I am waiting to get the attachment via mail. Please send the code as attachment to the above mail id

Thanks
EJ
 
S

Steven Cheng[MSFT]

Hi EJ,

I've just send the attachment(the webbrowser's wrapper winform control's
project) via the
(e-mail address removed)
Address, please let me know if you've got it.
You can rebuild it on your side before using it. As for the page to use
it, it's very simple , just add the following tag in page source:

<object width="100%" height="100%" id="MyWBMain"
classid="http://webservername/webapplicationname/WBLib.dll#WBLib.MyBrowser"
VIEWASTEXT></object>

Note that I put the WBLib.dll and all its dependence ( the interop com
wrapper for the webbrowser control) in the same folder with the page using
it.

And as I've mentioned, your problem is probably caused by security issue on
the client machine. Because by default the embedded webbrowser control will
not be allowed to execute in clientmachine's IE hosted CLR enviroment. You
need to add a codegroup for the certain assembly(using the .net
configuration tool in the Administrator tools ), you can add an codegroup
under the LocalIntranet_Zone and specify its evendence with Url and specify
the url with the certain assembly's path such as
http://webservername/webapplicationname/WBLib.dll
or you can even specify the upper level path such as
http://webservername/webapplicationname/*

and grant FullTrust with this codegroup. Thus, the assembly from this url
will have FullTrust permission to run in the client's IE host CLR
enviroment. Also, I've attached some screenshots in the mail. If you have
any questions, please feel free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
G

Guest

HI Steven

Thanks, I received the mail which u sent.

I followed the steps which u listed out, but still all other WIndows User controls works fine, except the Windows User Control which contains Webbrowser Control.

No error also coming, what can be done?

What can be the problem? What is the solution for this?

Please let me know, really we are stuck, early response will help us

Thanks
EJ
 
S

Steven Cheng[MSFT]

Hi EJ,

Thanks for your followup. I still think the problem we meet now is due to
security setting. I'd like to correct one thing I mentioned in the last
reply.

I mentioned that you can create the codegroup and specify the Url evidence
as
=======================
the url with the certain assembly's path such as
http://webservername/webapplicationname/WBLib.dll
or you can even specify the upper level path such as
http://webservername/webapplicationname/*
=======================

I've tested and found that they not worked and we have to specify the url
from the website's sitename such as

Http://webservername/*

Please try changing the codegroup's url to this style to see whether it
helps.

Also, one more simple way to confirm the security issue is adjusting the
LocalIntranet_Zone's Permission set,
change the "LocalIntranet_Zone"'s trust level to "FullTrust" , and then
test again to see whether it works. I've also attached the screen shot for
this means via email, please also check it.
#notice that when we do some modification on security changes or in page
which embeded the wniform control, we need to close the IE and restart a
new one to test again.

Thanks.


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
G

Guest

HI Steven

Thanks for the response. But I have not rcvd any images with the email

I have sent the Webapplication where I am using the User control containin
webbrowser Control(which u had sent) . So U can also test it in ur system
If anything else other than security problem, let me know

I have given permission to IP address of the system(eg: http://x.x.x.x
under codegrup in LocalIntranet_Zone. In the ClassId property also, i hav
given http://x.x.x.x as path for DLL

Let me know, how to solve this problem

Thanks
Van
 
S

Steven Cheng[MSFT]

Hi Vani,

I've receieved the project. I would have a try as soon as possible. Also,
during the time, you can also try
changing the LocalIntranet_Zone's trust level your side to see whether it
helps. I'll update you as soon as I've got some new updates. Good luck.


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
G

Guest

HI Steven

Thanks

I have given FULL Trust in both Internet Settings(for Trusted Site) and as well as under Codegroup

But still it does not seem to work. I tried to debug, but it does not go inside the User Control Code at all

What is ur system Configuration? I am testing it on Windows 2000 with IE 6 with latest patches.

Still I have not received the Screen Shots which u had sent in the previous mail

Hope this problem will be solved atleast by today

Thanks
Van
 
S

Steven Cheng[MSFT]

Hi EJ,

I've tested the WebApplication you sent me. I attached it on a W2k
server(SP4) machine and create Virtual DIR to host it, and viewing the page
which contains the Winform control. I haven't encountered any problems. It
worked fine.
Currently I haven't any definite ideas, I've resent the mail(contains
screen shot on adjust the client machine's LocalIntranet_Zone" 's trust
level in .net configuration tool.
#notice that if you have installed both .net 1.0 and 1.1 framework on the
machine. Make sure that you are using the .net configuration tool 1.1
rather than the old one.

And here is a kb article on how to debug IEHost Object issues
#HOW TO: Use the IEHost Log to Debug .NET Object Hosting in Internet
Explorer
http://support.microsoft.com/?id=313892

I think you may make use of the log mentioned in it to trace the acutal
error at client machine.

Also, I've found that you've posted another new thread titled
"Subject: ThreadStateException problem"
in the group. I'll also posted my reply there. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
G

Guest

HI Steven

Are you using Windows Server 2000. I am using system with Win 2000 Professional with SP4. Is this is the problem?

For me the page is not displaying the user control on the same system where it is developed and hosted as well.

Anyway i will use the IEHost Dll to debug the application and let you know

What else could be the problem? Why it is showing up the controkl in our system

Thanks
E
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top