Adding System.windows.Forms reference into asp.net website - asp.net

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.

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

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

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

yes, you can do it,just copy the
system.window.form
dll into your web Bin Folder
everything will work fine.

Related

HttpContext.Current.Session seems to be reset when embedded in Sharepoint Web Part

We have an internal ASP.NET web application - it's hosted by IIS but embedded into Sharepoint via Web Parts. It needed some tweaks, so I made the tweaks and tested it all on IIS Express via Visual Studio; all is well.
I've come to deploy the app onto a newly built UAT server (since this app didn't have one existing), and there I run into problems. Certain data is stored in HttpContext.Current.Session["__MySession__"] - for example a drop down control might be set to a particular value which is then stored in the session to persist across page refresh. The problem is that when embedded in Sharepoint, that persistence doesn't seem to work (and so the application behaves strangely). When you access the application directly by navigating to its address, everything is fine.
Now; the production Web App does not have this problem, even when embedded into the UAT Sharepoint site. That being the case, I'm pretty certain that the problem lies in how I've configured IIS. I can't see any difference between the UAT and Prod servers though, so I'm lost for ideas about where to go from here.
What could cause the application to "forget" its session state in this manner? Particularly only when embedded into Sharepoint?
Try to set the below code in your web.config file:
<pages enableSessionState="true" enableViewState="true" enableViewStateMac="true" validateRequest="false" pageParserFilterType="Microsoft.SharePoint.ApplicationRuntime.SPPageParserFilter, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=*******" asyncTimeout="7">
and
<modules runAllManagedModulesForAllRequests="true">
<remove name="Session" />
<add name="Session" type="System.Web.SessionState.SessionStateModule" />
</modules>
You could refer the below thread for more detail:
https://sharepoint.stackexchange.com/questions/83784/session-and-httpcontext-not-available-in-web-part
https://social.technet.microsoft.com/Forums/msonline/en-US/3145fd29-2315-42f7-8f9d-cf6d52dc3c95/enabling-session-state-in-sharepoint-2010?forum=sharepointgeneralprevious

Why am I receiving a "type could not be found or is not registered as safe" error for my iframe web part?

I am working on a farm solution in sharepoint 2013. I want to open a page in an iframe that has been passed a URL as its src.
So I made a visual webpart with a .ascx file which looks like this:
<asp:HtmlIframe id="frm2" runat="server" src="" height="600px" width="900"></asp:HtmlIframe>
And in the server side code (ascx.cs) I set the src property like this:
frm2.Src = "http://wwww.google.com";
However, I the web part generates the following error:
Web Part Error: A Web Part or Web Form Control on this Page cannot be displayed or imported. The type SharePointProject2.Employee.Employee, SharePointProject2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b6ac6e2971e56b29 could not be found or it is not registered as safe. Correlation ID: c41f8d9d-2f85-509f-fa04-e1d0062edc96.
On going through problem I found various solutions like this to add this to a web.config file.
<Assembly Location="MyAssembly.dll" DeploymentTarget="GlobalAssemblyCache">
<SafeControls>
<SafeControl Assembly="MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3b7ec4bdc16ce8b2" Namespace="Myblog.WebParts" TypeName="*" />
</SafeControls>
First Of All their is no web.config file in my sharepoint project
Whenever I open the project in empty farm solution no web.config file is there.
So I manually made a web.config file which is the xml file and add some code to it.
My application when running on Windows Server R2 is working well, and all the people can view it which are there in Active Directory, but when I stop the application then the same error comes in safe mode.
Please help me understand how to open a external application (to which I have a URL) in iframe using server side code on SharePoint.
What approach should I use, with the need to use server side code and in provider hosted server?
Thanks In Advance Guys
Basant Gera
​​

Adding Assembly to ASP.Net website

I want to use the Task Scheduler Managed Wrapper in my ASP.Net project so that I can access the windows task scheduler from within my website. From what I have learned so far I need to add a reference to the assembly dll to my web.config. is that right? How do I figure out the public key token for the assembly file though? Is there any other way than using the 'sn.exe' utility, because I don't have the .net SDK installed and I unfortunately have no option of doing so on this computer. Thank you for your help!!
You shouldn't have to do anything with sn.exe or the public key token.
If you are working in a Web Site, right click your web-site in the Solution Explorer and click "Add Reference". It will create a Bin folder for you if there isn't one, then add the assembly to the bin.
If you are working in a Web Application, use the Add Reference dialog by right clicking "References" in the solution explorer.
EDIT:
thank you but i am not using visual studio at all. all i have is IIS and I use notepad for editing. the server side portion of my website is written in jscript.net
You will probably be adding a Reference with the web.config then, such as:
<system.web>
<assemblies>
<add assembly="YourAssemblyNameInBin" />
</assemblies>
</system.web>
Place your assembly in the Bin, and change YourAssemblyNameInBin to the name of the assembly on disk without the extension.
You don't have to include the version, culture, and public key token of the assembly. If you want to though, you can use the sn.exe tool to display the public key token like so:
sn.exe -T "PathToAssembly"
Note that the T is capital. If the assembly is not signed - then you must omit the public key token from the reference.

Routing with Web Forms - Could not load System.Web.Routing

I am using:
ASP.NET 3.5 SP1 with Web Forms
Routing thru Global.asax (System.Web.Routing and RegisterRoutes)
IIS 7
Everything is working fine in my local machine, but it gives the following error in my hosting environment:
Could not load file or assembly 'System.Web.Routing, Version=3.5.0.0, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
I did everything inside my web.config file mentioned in the following link:
http://msdn.microsoft.com/en-us/libr...8VS.90%29.aspx
But I am still getting the above error.
What else am I supposed to do fix the error?
Thank you for your help!
It could be possible that some settings in web.config are missing which are necessary when you host your application in IIS. Take a look at this article, especially Figure 2 which describes the configuration entries for IIS 7.
I remember that in ASP.NET 4 setting
<modules runAllManagedModulesForAllRequests="true" />
was enough and adding the modules and handlers in Figure 2 of this article wasn't required. But in ASP.NET 3.5 it might be necessary.

Why can't you build a website in release mode?

In ASP.Net, if I set up a web application I can configure it to be in release mode but with a website I can only set the configuration to be in debug mode. Why is this?
In web site projects each page is compiled dynamically upon first request. It will compile without debugging symbols unless you specify otherwise in the config file.
A Web Site's debug/release is controlled by the Web.Config file:
<system.web>
...
<compilation debug="true">
...
</compilation>
</system.web>
Set debug="true" for debugging, set debug="false" for release.
Probably because a Web Application compiles the whole website into one DLL. To run and debug pages requires recompiling the entire application. Whereas a website project compiles dynamically at the page level.
For websites one releases the source code to the site, there is no build to be done.
The code is built on site.

Resources