how to serve .net console on Nginx? - c#

So I got it to the stage where the .net (framework) console application could run on localhost, but the next issue is exposing it using Nginx.
I looked at many tutorials, but they all seems to be for websites. How can i make it work for a console app?
Thank you.
What do you gain from using nginx in front of it instead of just
opening the console app on port 80 (or preferably 443 witha
certificate)? You will probably need to set up nginx as a reverse
proxy for your app.
I have the console app running on port 1234 because there is already an app using port 80. To be honest, I am not sure why I am using Nginx, I just assume that's what I need, since I have the app running on localhost but I cannot access it from outside. I have set the firewall to accept that port from the domain provider side.
uhm.... what exactly do you mean by "exposing a console application"?
because what you expose with nginx - or any other webserver - is a
website. also: welcome to stackoverflow. i recommend taking the tour,
as well as reading how to ask a good question and what's on topic.
Thank you. I am probably not using the most accurate term. Basically, I just want people to be able to access my app. In my mind, I imaging there is some additional setting I need to do to have it "exposed" to the public (and that's using nginx). I can see the app running on localhost but not sure why it's not public.
please say what you expect a console app 'exposed to the public' would
look like. How would they access it? What tool on my desktop would I
start, ignore the nginx part of the discussion
So I have a loop serving some web content similar to this one.
https://gist.github.com/define-private-public/d05bc52dd0bed1c4699d49e2737e80e7
When I run it, external user should go to a website and see the page content served up by this.
If your console app is a Console.ReadLine() Console.WriteLine() type
thing the only way to expose it simply is to setup and SSH server on
your host system. Then the users need an SSH client to access it. This
is doable via web browser hosted SSH access but thats v complex
solution
You can ignore all the Console Readline and Writeline stuff.

Ok, so the solution is actually quite simple. All you need to do is forward your incoming request to a localhost using proxy_pass, as suggested by #fredrik. The following should be added to the default config file (under nginx):
server {
listen 80;
listen [::]:80;
server_name example.com;
location / {
proxy_pass http://localhost:8888/;
}
}

Related

Making a proxy to block websites

I am making a proxy for Windows. I would like to be able to block certain documents under specific URLs.
For example, everything on google.com would work fine, but google.com/index.html could be blocked.
Can anyone help with this please?
I want the proxy to run on the same PC that uses it.
I have found what I needed. Sorry if I wasn't specific enough.
For any future users who come across this post and know what they are after - try FiddlerCore for .NET applications. It's a great package enabling you to capture and 'fiddle' with HTTP and HTTPS responses before they reach your device.
This means that FiddlerCore can be used to analyse a request's header, check for a certain URL and then drop the request.
There are two methods:
(1) using FiddlerCore package
(2) modification of "hosts" file
1)
FiddlerCore is a .NET package which is used to analyse packets in the network.
A deep knowledge in FiddlerCore is required because it contains dangerous functions as well as most helpful functions.
2)
You can block websites by appending curresponding URL to the "hosts" file.
Navigate to C:\Windows\System32\drivers\etc, changing C: to whatever drive letter you have Windows installed on. Select "hosts" to open it.
Just append in a new line :
127.0.0.1
You want to get Administrative privilege for your application to modify the hosts file.

Create a file from the browser

I'm looking for a way to establish a simple communication between a c# web application and the operating system.
Since i'm working on Silverlight, i get everything i need to create files into any folder on the C:/ Disk. The problem is that we're going to migrate from Silverlight to Html 5 / C#
So i'd need a way to create files FROM any browser to any OS : Windows,Mac,Linux ..
I thought about using Microsoft Active X but that's not cross platforms.
I'm simply looking for a technology/plugin/software or anything that would allow me to do that, the less client interaction would be the best.
I think your need is in conflict with any common sense about security. If there was a simple way to create any file on any computer that loads your web app, just imagine how quickly all sorts of malware would spread.
But going back to your question - I think it will not be simple (btw. was it really simple in silverlight?). What I can imagine is to have some kind of service running on a client PC (the user would have to install it, or it could be corporate policy if your web app is targeted at corporate solutions). Then the service would listen on some TCP port and your web app could send requests to that port with the intent to create particular file with particular content. All the security concerns would be then implemented in mentioned service so that it doesn't get abused by hostile web apps

Fiddler Not Capturing Traffic from my C# Application

I am having problems capturing traffic sent and received from my C# application.
The application is an ordinary WinForms application using C# 5.0 and .NET 4.5. .
Fiddler captures traffic from Chrome and Firefox with no issues, just not my application. I have also loaded another application that I developed, and that works fine.
It may be worth noting that this is the first application I've developed that uses HttpClient to make Http requests. Could that be causing any issues?
To be clear the Fiddler Application monitors the traffic. I am not connecting to localhost. I am connect to web API's.
Step #1 is to try starting Fiddler before starting your application. This helps the default configuration, whereby .NET applications pick up the system proxy when they start and are oblivious to proxy changes after they start.
Step #2, if the first step doesn't work, is to explicitly configure your process to use the proxy by editing the app.exe.config file or the machine.config file, or by setting the Proxy property on the request object.

C# Web Server for displaying Console Output?

I have just finished writing my c# console application, and I am contemplating embedding a web server into it (probably this one http://webserver.codeplex.com). I don't do much in the way over advanced web coding though, so I am not sure if I can do what I need to.
Basically, I would like to allow users to view the console output of my application in realtime just by visiting the site being served by my application. If I understand correctly, to do something like this it would require AJAX, which a simple C# Web Server wouldn't be able to handle.
Is this correct or is there an easy way to do this I am missing?
How to re-route console output
You will need to write your own TextWriter and make Console use it via Console.SetOut. This writer should notify connected web clients, as well as the original Console.Out.
How to host a COMET-like server
You can use HttpListener and some basic async programming to do this. If you wrap the HttpListenerContext.Response.OutputStream in a StreamWriter (with AutoFlush set to true) and set HttpListenerContext.Response.SendChunked to true clients will receive partial results - this means you can even do it in an IFRAME.
You will need to add rights to the URL for yourself if UAC is enabled:
netsh http add urlacl url=http://+:9090/ user=domain\username
Code?
I couldn't resist it; I have written a (poorly tested and mostly incomplete) sample.
That is incorrect.
AJAX is a client side technique relying on JavaScript. As long as the web server can respond to an HTTP request, it can server AJAX content (whatever that might mean:-).
I would use this UtilDev Cassini as me embedded web server of choice, it is based on the code from the embedded Visual Studio dev server and can run pretty much anything that runs in IIS. AJAX is a browser technology not a server technology, the server just sees http requests the same as any other. My last point would that it seems slightly odd to embed a web server in a console application. It would be more usual to do this with a windows service. Have you considered converting the console app into a windows service?

asp/php communication to local service/application

I have a local application which parses data. What i need is to develop a web interface to query statistics and set configurations for the application thats running at all times. Since I am the developer of both applications I have full access to both source.
My main goals here are:
- have a service or app running at all times on the webserver doing most of the work
- have a webUI which will connect to this app and display stats and make configurations
- service/app will be writen in C#
- WebUI will be written in asp or php
- the WebUI must be accessable through the web domain ie: http://server/TestApp on default port 80 were there are other web apps running already.
I know there are ways to do this using a specific port to communicate to eachother, but i would like to avoid this. What is the best way to communicate between these apps?
Thanks,
-Stewart
Use a FileWatcher in C# to watch a file that PHP can read/write to. When something needs parsed, you can try it that way.
You could also give PHP permissions to exec or use the ` character to execute your program which return the result to a varible ex:
$var = `C:\What\Ever\program.exe $param1`;
The local port listener is not a bad idea though.

Categories