I have a asp.net application where i use System.Windows.Forms namespace reference to use web browser control.the application runs fine on local system but after hosting it shows error. How do i embed the dll for to use in the web application.
-
1You can't do this. What are you trying to achieve? – ChrisF Jun 01 '12 at 12:44
-
Are you just looking for another web window on your web page? – Gage Jun 01 '12 at 12:47
-
2How were you anticipating using a web browser within a server-side application? – Jon Skeet Jun 01 '12 at 12:49
-
Hi @JonSkeet, you can use the web browser to make screenshots for thumbnails/previews. As far as I can see this is the only native way to do it within the .NET framework. – Dirk Boer Aug 11 '16 at 09:31
-
@DirkBower: Assuming that's for testing, I wouldn't put that into the web application itself. Unfortunately the OP never got back to us about what they were trying to do. – Jon Skeet Aug 11 '16 at 09:48
-
@DirkBoer: (And if it's not for testing, that sounds like it's probably a bad idea. I wouldn't want a web browser running possibly dubious code on my server.) Apologies for the typo in your name earlier, btw - the perils of using a mobile with no autocomplete for @ comments. – Jon Skeet Aug 11 '16 at 11:03
-
Hi @JonSkeet, can't answer for the OP, but I hit the same problem. I am using it within a web application atm - and it *does* feel quite dirty, but I haven't found another way yet. Would still be a good idea to make this a separate microservice. About the dubious code, shouldn't such a webcontrol be hardcore sandboxed? Or am I missing some other vulnerability? – Dirk Boer Aug 11 '16 at 22:02
-
1@DirkBoer: I wouldn't want to assume anything about how well sand-boxed the control is. But if you want it to look how a web page would actually look, that will involve running Javascript, and I wouldn't personally want to do that on a server without it being *very* carefully controlled. (For example, you'd want to give it a very small amount of CPU to use before killing it.) – Jon Skeet Aug 11 '16 at 22:05
-
Hi Jon, thanks a lot. Good point, unnecessary risk. I see if I can move it to a fully sandboxed (stateless) microservice that has no access to any resources. – Dirk Boer Aug 12 '16 at 09:08
4 Answers
Answering a 3 1/2 year old question is pretty weird...
I. In your web.config, add a reference to Windows.Forms
<system.web>
<compilation>
<assemblies>
<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</assemblies>
</compilation>
<system.web>
This only works if the referenced DLL is in the GAC. If it is not:
- Create a
/Bin
folder in your website root. - Copy your DLL there.
- Do not add a reference in web.config.
II. In your module/class, import Windows.Forms (VB: Imports / C#: using)
Imports System.Windows.Forms
You can now use the web browser control. It's a bit tricky, though.
Possible uses include: generating screenshots, AJAX crawling (#! >> _escaped_fragment_) etc

- 3,495
- 1
- 17
- 18
System.Windows.Forms
contains classes for displaying things on the computer that the code is running on. When you are testing on your PC, it works because you run the browser on the same machine as your development server.
When running on a real server, anything in System.Windows.Forms
would be displayed on the server - not on the user's PC. (Besides it would be displayed on a hidden desktop in the server's service session).
You shouldn't mix webforms and windows forms. Whatever you want to do - there is another way that works, that doesn't involve winforms.
Don't use System.Windows.Forms
in webb applications

- 1
- 1

- 67,989
- 17
- 150
- 217
As previously mentioned, you cannot use WinForms controls with ASP.NET.
Use an iframe to show whatever page you're trying to display in the webbrowser control: http://www.w3schools.com/tags/tag_iframe.asp

- 3,946
- 1
- 19
- 32
yes, you can do it,just copy the
system.window.form
dll into your web Bin Folder everything will work fine.

- 1
- 1