开发者

Is there a way to program in c# such that when an exe runs, it serves and handles requests on localhost

开发者 https://www.devze.com 2023-01-04 11:49 出处:网络
I want to make a program that hosts a w开发者_开发百科ebpage with computer uptime of the system it is running on but I don\'t want to do anything to the user\'s IIS. Is there anyway to do by making so

I want to make a program that hosts a w开发者_开发百科ebpage with computer uptime of the system it is running on but I don't want to do anything to the user's IIS. Is there anyway to do by making some system calls (to the ISAPI dlls etc) in c#?


You want to create a web server?

Try System.Net.HttpListener

You can get the system's uptime in milliseconds using System.Environment.TickCount


Take a look at the HTTPListener class: http://msdn.microsoft.com/en-us/library/system.net.httplistener.aspx


Just serve the page yourself - a simple web server is not hard to write and there are a lot of examples available on the net; from extremely simple to quite advanced. For example this one.


If an alternative to IIS you seek, give Cassinni a try.


As has already been answered, HTTPListener is a good start.

However, you're quickly going to discover issues with firewalls and available ports, so ultimately I think you'll find that doing something to the user's IIS is likely the path of least resistance, at least on systems where IIS is already running.

If IIS isn't an option then you will either need the app itself or an installer to configure Windows Firewall to allow incoming connections. They also may have other software and hardware Firewalls in place which need configured.

0

精彩评论

暂无评论...
验证码 换一张
取 消