7

I just need to create an extremely basic web server that will basically allow me to go to http://1.2.3.4:8080 and browse a list of files in C:\web or something.

I found this http://mikehadlow.blogspot.com/2006/07/playing-with-httpsys.html which looks perfect but I ran into a couple of questions.

1) When I replace the IP with * or + like the documentation says, I get access denied errors in system.dll. When I use localhost or my local IP it works fine. Why is this? I would like to potentially be able to bind it to a specific IP address on machines that have more than one.

2) I am probably missing something, but how do you specify the core directory where the files are that it is serving with this code?

stivlo
  • 83,644
  • 31
  • 142
  • 199
Michael Pfiffer
  • 145
  • 3
  • 7

4 Answers4

4

re 1: because you dont have permissions to register this url. Use "http add urlacl2 to register permissions for your user (as admin) to make the binding. Example: http add urlacl url=http://+:8080/ user=DOMAIN\UserName

Re 2: You dont. THat is pretty much your code. Http.sys does not read from a file system - it is a driver. Your application must read the files and answer the request.

TomTom
  • 61,059
  • 10
  • 88
  • 148
  • 1
    +1. Although on win 7, I needed to run "netsh http", and then "add urlacl url=...". Typo? –  Apr 25 '12 at 19:40
0

This might be a little overkill for what you want, but check out the aspNETserve web server project.

It is open source, so at the very least you can browse the code to get some ideas.

TWA
  • 12,756
  • 13
  • 56
  • 92
0

I know this does not help you with your code problems, but why re-invent the wheel! I think you should look at using IIS Express, as I think it could meet your needs nicely:

http://learn.iis.net/page.aspx/868/iis-express-overview/

IIS Express is a standalone executable that will provide all the functionality you need. It will also run on Windows XP and above.

Nathan Anderson
  • 6,768
  • 26
  • 29
  • Interesting find, I didn't know about IIS Express. Thanks. – TWA Feb 09 '11 at 23:27
  • And if you need a Full blown, free, commercial-grade web server, used by millions and millions around the world, you can install Apache. – Icarus Oct 05 '11 at 05:35
0

Here's a Simple and Secure C# Webserver, offering Digest authentication without the need for Active Directory. Digest Auth is broken, but it is not practical to crack with passwords over 18 characters, anyway one can see how to make a webserver using C# and .NET HTTP.SYS which was the point of this question.

https://git.motes.camp/web/index.php?p=DigestAuthWebServer.NET-HTTPSYS.git&a=summary

clone url: https://git.motes.camp/DigestAuthWebServer.NET-HTTPSYS.git

Motomotes
  • 4,111
  • 1
  • 25
  • 24