How to call Windows form from .net web application - c#

i have a windows application and now we want to upgrade it to web application.
Is there any way to use same forms from web application
to avoid duplicate work to develop same page in web application.
i want to open windows form on one click from web form. please provide any sample code if possible.

It's not something you can do automatically. You can reuse your business logic behind the application but you have to write a new UI from scratch. You can also try to use some automated tools but to be honest in most cases you will have to put significant amount of work to get your application working the same as window windows application. You must consider and implement new security policy regarding data transfer/presentation in your web app.

As Adjorem said, simply, no. Even if you find a converter it will probably make a mess and you'll need to do a lot of refactoring.

To open your windows app from web app:
You can register your own url protocol to start your application, e.g myfancyapp.
On your website you can create an href="myfancyapp://...". You can parameterize your windows app through a downloadable file with startup infos.
See:
How do I register a custom URL protocol in Windows?
If you want, you can check, if your app is installed with the help of fonts. Install a font (with a special name) with your app installer. You can then check if font is available on your website and display a message "Please install windows app first".

Related

C# WPF, and data exchange with the browser

I've a C# WPF application developed in VS 2015, and I want the browser to read some data from it. Just a short string. I can save it in a text file, or in a variable but it should be visible to the browser (using JS I suppose). For instance using file:/// doesn't work if the original page is hosted online - as in my case (different source conflict). This should work in Opera and FFox, but looking at their extensions, it seems you can only develop with front-end technologies, which are not enough in my case since I use WPF to look into Win OS, and then I need to share the result with the browser.
I suspect it's possible, and no , it's not to write a malicious piece of code. For instance I can read the details of the graphic card for diagnostic purposes.
Please help, many thanks.
Browsers run in a security sandbox which is intended to stop them reading or writing files to the file system.
You could write to the user's appdata. There are various javascript frameworks which persist data to there so they can provide offline or static data.
I don't think that is a good plan though.
I suggest your first candidate would be a cookie.
Quick google on how to do that, I find:
How to create cookie in c#.net windows application?
From a web page you can use the content of a cookie dynamically. So you could change what you see in the web page after it's up and running from some process in your wpf app and do a counter or whatever.
I've not used this with windows apps and a browser but I have with a web app and Silverlight. I'm afraid I don't have that code to hand though.

How to open .exe file On client system in a Web Application

I am developing a web application, Here I want to open .exe on client system from server, that means after hosting my site in IIS. Is it possible to open for example notepad or windows media player on client when the user clicks on a link on my web site?
This is not possible. And if it will be possible - it should be removed immediately.
The reason for this is simple - security, it means almost everything if you working with browser.
If you want to launch some external executables - just make WPF or WinForms application client, and talk with WCF service. This way you will be free to use everything you want on client side.
It's a common scenario in some cases. mailto: url scheme is an example. When you click on such links, your default mail application will open. Or as another example you can see such feature in SharePoint applications which opens OneDrive for Business for synchronizing documents or use other office applications. Also skype: is another example.
To have such feature in your application you can use either of these options:
You can register an application to a custom URI Scheme, then you can activate that application by the specified URL and pass parameters in URL. For more information take a look at:
Registering an Application to a URI Scheme.
You can use a ClickOnce deployment by specifying an installation URL. Then you can simply open the application using that URL and pass parameters to the application using query string.
For more information take a look at:
How to: Specify the Location Where End Users Will Install From
How to: Retrieve Query String Information in an Online ClickOnce Application
Warning
Be careful! You may introduce security holes to your application and clients. When passing data be careful about security vulnerabilities like Injection, Insecure Direct Object References, SensitiveData Exposure, and so on.
Especially if you want to use such protocols to create a middleware to open a program which is not yours, you should only expose a minimal secure set of features of that program and pend the operations to users confirmation. For example mailto: activates the mail program with some minimal data but doesn't send email. The users should press send themselves.

Testing WPF simple application on multiple web browsers

I'm newbie in WPF/Silverlight world. In the first step , I developed a "Hello world" application and simply run it but the problem is application successfully run only on Internet explorer. When I changed my browser like chrome or firefox etc, application pop up a Save window which means browser unable to understand the filetype. I want to know any plugin required to smothly run my WPF project on different web browsers.
IMO, You are referring to Silverlight and not WPF
WPF Applications are Desktop Applications and they are not made for Browsers.
And Silverlight is cross-platform, across browsers.
You can download and install the plugin from here,
http://www.microsoft.com/getsilverlight/Get-Started/Install/Default.aspx
I think you are looking for Silverlight, not 100% sure tough
WPF browser based application can run in the IE and firefox web browser. One can use silverlight for implementing the WPf browser based application. But silverlight is the small subset of WPF framework. The machine running the WPF web browseer based application must be installed with the .Net runtime environment. WPF web browser based application ideally used for the intranet usages.

Security testing a hybrid web and desktop application

Setting the context:
We have an internal app that started out as a web application, but now uses the windows desktop model instead of the browser for rendering. So instead of opening in browsers, the web app opens in modeless windows that are coded in C#. The user has to install a small exe to setup the modeless windows.
You would be clicking custom built toolbars (instead of the File, Edit, View options etc) and those will launch modeless windows and trigger an HTML request. The reponse will be rendered in the modeless window.
Issue:
we used to security test using Appscan when it was a pure browser application. We also use pen testers. However, Appscan doesn't work with the modeless windows model. It only manages to capture the first request (which is usually the login request).
Would you happen to know of any tool or testing framework/model that can security test this kind of an app?
I did try to look at relevant links, but they all seem to point to pure browser based web testing. Like this one: Web application security testing
Thanks in advance!
Edit: An example - have a look at http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/showModelessDialog.htm
How would I get appscan to scan the request response in the modeless windows.
What needs to be tested (for security) beyond the login? You've essentially created a dumb terminal that passes commands to a server and renders responses from that server.
If you really need some automated tester to work, then create a command-line switch for your EXE (dumbtermina.exe /test) that renders a regular windows form with simple buttons that simulate all of the menu and other commands.

How can I publish a web page from a Windows Forms application? (C#)

I wish to build a Windows application that will generally run in the background, but have a configurable front-end Windows Forms GUI. I also would like this program to publish a small web page which can be accessed from other machines/devices and interact or call functions of the server application.
I'd rather not deploy a full-fledged ASP.NET web site with IIS, etc. I just need something simple.
So how would I go about doing this?
Take a look at Kayak. It's a relatively small and lightweight HTTP server that you can embed into your application and should provide all the functionality you're looking for.
FWIW, I am in no way associated with this project.
Maybe it's just because i've been doing asp dev for years, but I really think you should go the iis asp route as its very simple and built into windows. I can't imagine a more straightforward way of serving a webpage that has c# behind it to programmatically effect the host system.
Thanks to Kev in the comments on my question, he pointed me to this question, in which I found a link to a lightweight C# HTTP server component I could just drop in to my application: http://webserver.codeplex.com/
Works well for little stuff like I was doing.

Categories

Resources