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 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
 
G

Guest

HI Steven

Sorry for getting back late. Thanks a lot Steven. Finally it is working fine after setting the Full Trust under Adjust Security Policy. Once again Thanks a lot for your patience and continuous supprt

Now it is working fine. But I have some more queries on the same

1. We are opening the webform containg Webbrowser Control in a popup window. On click of a button in the User control I am opening the external URL. Now our external URL needs User name and password inputs to login to their system. I am using Navigate2 method of axwebbrowser control, which returns void. I want to check whether the navigation to the external URL is successfull or not. How can do this check

2. Inside the UserControl I am saving some data to a file. Now I want to give the path where I want to save that file. I don't want to hard code the path inside the User Control. Also since this user control runs on client's system, I want to save the file on the server where the application is running, not on the client's system. So I want to pass the server Folder Path where I want to save this file. Also I need to connect to the Database on the application server from the user control, How can I do this

3. I want to close some of the objects on unload of this user control, how can I do this, Can I do it on Dispose

If you want to create this in a different thread let me know.

Thanks
Vani
 
S

Steven Cheng[MSFT]

Hi Ej,

Thanks for the response. It seems that you've got the winform control
displaying in web page, yes?

To answer your question in last reply here:

1. We are opening the webform containg Webbrowser Control in a popup
window. On click of a button in the User control I am opening the external
URL. Now our external URL needs User name and password inputs to login to
their system. I am using Navigate2 method of axwebbrowser control, which
returns void. I want to check whether the navigation to the external URL is
successfull or not. How can do this check?
================================================================
If you want to capture the state when the navigate or navigate2 method is
completed, there are two useful events
NavigateComplete
NavigateComplete2
We can add handler for either of them so as to do some operations when the
navigation to a certain webresource or document is completed. Here are some
useful weblinks:

HOWTO: Use the WebBrowser Control to Open Office Documents with Visual C#
..NET
http://support.microsoft.com/?id=304662

#Using the WebBrowser control, simplified.
http://www.codeproject.com/miscctrl/simplebrowserformfc.asp

2. Inside the UserControl I am saving some data to a file. Now I want to
give the path where I want to save that file. I don't want to hard code
the path inside the User Control. Also since this user control runs on
client's system, I want to save the file on the server where the
application is running, not on the client's system. So I want to pass the
server Folder Path where I want to save this file. Also I need to connect
to the Database on the application server from the user control, How can I
do this?
===================================================================
Since the Winform UserControl is running in the clientside, so we're not
able to generate the serverside path in winform control's code. MY
suggestion is we use the <object ... > 's <param> tag to set the paramter
for the control via asp.net code, for example
<object ...>
<PARAM NAME="BasePath" VALUE='<%= Server.MapPath("~/pic") %>'>
</object>


3. I want to close some of the objects on unload of this user control, how
can I do this, Can I do it on Dispose?
=======================================================================
Since the IE host winform/activex controls are in IE host enviroment, IE
will control their life cycle. and Generally when a certain browser's
instance ended, the in memory resources will be released. And as for the
winform control, you can make use of its dispose interface to release some
objects.


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
 

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