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

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.

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 can I create a WCF service that allows users to connect to my service through a web browser and upload a file?

I've created a Hello World WCF service that uses the ASP.NET Development Server - I launch the client which opens a page in my web browser, HelloWorldService.svc, then this triggers the command prompt to open and print out a Hello World message.
I don't fully understand this chain of action or how it's useful.
I'm trying to create a WCF service that acts as a server that allows users to connect to the server and perform a file upload - I will take this file and store it locally on my machine.
For now, allowing this to work locally on only my PC is fine but I really don't know where to begin to accomplish this. Any advice would be appreciated.
EDIT: I NEED to use WCF. So please don't suggest alternative solutions.
WCF is arguably overkill. Simplest case, just use the standrad .Net FileUpload control.
Here are some examples:
ASP.NET File Upload
http://asp.net-tutorials.com/controls/file-upload-control/
Which leads to the question "When should I use WCF"? Here are a couple of answers:
When & where I should use WCF
http://forums.asp.net/t/1480028.aspx
http://msdn.microsoft.com/en-us/library/cc512038.aspx
http://forums.asp.net/t/1478962.aspx
Finally, here are a couple of links that describe WCF-based file transfer services:
http://www.codeproject.com/Articles/166763/WCF-Streaming-Upload-Download-Files-Over-HTTP
http://code.msdn.microsoft.com/windowsdesktop/Upload-files-using-a-REST-13f16af2

Gmail-like notification Service in ASP.NET/C#

I have a web-based application developed in ASP.NET. It is a business application and people do regular deals & transactions from this portal.
The application has two types of user:
1) Front-office User - who makes the deal
2) Back-office User - who look at all accounting & voucher generation work for the deal
The current problem is, to check a new deal created by a front-office user, the back-office user needs to refresh the web page every few minutes, which is very time-consuming.
I want to develop a small windows-based notification service through which I can show them notifications without going to the browser. It will be in the same manner as the Gtalk desktop tool, which notifies us of newly-received mail.
So to achieve the above thing what should I use and how to use & implement the solution ?
I need to develop the solution using .Net framework
I would look into SignalR and use that to keep a persistent connection open to your server and notify the client when new data is available. If you use SignalR, you don't even need a windows application, you can use their javascript client and show the notifications directly in the browser (you can of course still go the Windows Application route as well).
If you are in a cloud hosting environment, your cloud provider should have a service of use for you as well.

What are my options for sending data from Windows app back to developer without using a webserver

I am writing a simple WPF quiz application for a family member and he would like users of this application to have the option to send him their scores once they have completed the quiz. I was hoping to do this without the need to create some kind of webservice for the app to talk back to.
My initial idea was to email the results back, but that runs into problems. What if there is no SMTP client on the user's machine? I don't want to embed a password for a public smtp server into the application. I could do a Process.Start("mailto:..."), but that requires their machine to have a handler for mailto: and for them to click submit on the generated email.
Another idea I had was that the app could add a line into a Google docs spreadsheet, but that would mean a google docs password would need to be embedded in the app.
So my question is, without me writing a separate application running on a webserver for my WPF app to talk to, is there a good way of my app sending data back to me that doesn't require a password? I'm guessing there must be some kind of public webservice I could use for this?
If you're happy with a third party service that can do this for you, consider Parse, or any other 'backend as a service' provider.
You should then be able to implement something else that reads the saved data from the service when required, without having to expose itself as an API.
Create a google doc forms and when you need the user to submit their score, launch a web browser with the doc url. You can auto-populate the fields by query parameters( ... &entry_0=Barney&entry_1=Google& ... )

Pass arguments to Silverlight OOB app

We have a Silverlight application that requires access to peripheral devices - specifically, scanners. With this requirement, we're forced to use Silverlight as an OOB application. Up until recently we have been hosting our silverlight app online inside a .aspx page. We've been passing parameters to this application through the url (i.e., http://testsite.com/default.aspx?username=User&password=UserPassword&screen=Screen ). The SL app validates the username and password and if authenticated, opens up the "Screen" passed to it.
What options do I have to get this SL application working similar to the way I delineated above (as an OOB)?
Thanks,
-Tom
Instead of passing data in via the URL, you could have the application call back to a web service on startup to request this data. Or store it in Isolated Storage (but I don't recommend putting passwords there, Isolated Storage is not secure) and use that on startup.
Even if there was another way to pass start params to the OOB app how would you want a user to invoke this? Via some sort of link? A custom shortcut you create? Since a user launches an OOB app via the Start menu or desktop only, I'm not understanding what context would even really be available in these cases.
When you install a Silverlight application to run OOB, it creates a directory in isolated storage which has an index.htm page in it that actually "hosts" the OOB application. (It's described here: http://debuggingblog.com/wp/2009/07/17/silverlight-3-outofbrowseroob-explained-and-how-to-host-any-xap-package-by-modifying-the-metadata/). One way to do what you need to do is to edit that index.htm page, and pass in the parameters there. Of course, you'd need to figure out how to edit that page (likely hard to do automatically, unless you've got a setup.exe). Would it make more sense to just prompt the user for their userid/password? You'd only need to do it once -- after that, you could store it in a configuration file in some well-known location (presumably encrypted or at least obfuscated in some fashion).
The other possibility, if you are using Silverlight 4, is to store values into the Windows Registry. This is what we are using for username, database name, etc..

Categories

Resources