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?
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.
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.
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.
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
Related
We have a public website that is already exposed to the outside, although in reality there's really nothing there. Simply default.htm file with "Coming Soon" text in it. (http://vensuresoftware.com/)
We also have a WebAPI we've put together that we want to add to this website. When I publish locally to my IIS6, it works no problem. It's accessed as http://localhost/HRConnect/api/Claims just fine. I've used PostMan, a C# client, and Javascript AJAX to access this just fine. I can also load it in a browser at that URL, and I get the appropriate default controller and action.
However, I have been totally unable to accomplish this same thing on the website. Ideally I'd like to include it as a Virtual Directory to the http://vensuresoftware.com and access it as http://vensuresoftware.com/HRConnect/api/Claims but I've had zero luck doing so.
I have tried to add it as a Virtual Directory as well as an Application under that specific website, but when I access the URL, all I get is "The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."
I've ensure the Application pool is correct, with an appropriate user and the pass through connection test succeeds. But I just cannot access the service or the URL.
Any ideas or suggestions at all on what I can try? I'm not sure what else I can include here. Nothing special in IIS, nothing special in the service really. There's only 3 actions in it. As I said, it all works beautifully locally, under localhost though.
IIS 7 doesn't have built-in support for extensionless URLs which causes a lot of headaches trying to get MVC and Web API apps to run. I've gotten it to work using both these options. Pick the one that applies to you.
Install this IIS patch which allows IIS 7 to handle extensionless URLs.
If the patch isn't an option because you're worried about breaking other sites on the server, you can make the Web.config adjustment found in this answer. You'll have to do this for every MVC/Web API app you have running on the server.
I want to implement a restful service in ASP.NET. I want it to be compatible with .Net 2.0 and IIS 5+. I am constrained to not use ASP.NET MVC or REST starter kit. By reading on internet I have learned that it can be implemented using HTTPHandlers. The problem is, the request will come in as a POST request. And I want to URL to be like:
http://abc.com/MyService/MyMethod1/
and
http://abc.com/MyService/MyMethod2/
Any workarounds for this?
Thanks,
Vamyip
Your best option is to use URL Rewriting. This is non-trivial in IIS5. The methods I know of are as follows:
Method 1 - ISAPI filter
These are low-level modules that allow you to manipulate the incoming request. Programming one of these is hairy and tough to debug. If you go this route, you are better off using one that has already been built like ISAPI_Rewrite.
Method 2 - IHttpModule
These are managed ASP.Net modules that are easy to add/remove from your application. Again, you are better off using a pre-built component like UrlRewriter.NET. The issue with using one of these, (as BrainLy mentions), is that you have to configure IIS 5 to map all incoming requests to ASP.Net as follows (link):
Open Up IIS and Navigate to the “Home Directory Tab”
Select “Configuration”
Click “Add” and enter “C:\WINNT\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll” in the Executable box. For the file extension, enter “.*”. Finally, make sure that “Check that file exists” is not checked.
One interesting thing to note is that ASP.Net is itself an ISAPI module :)
Once you are able to manipulate URLs using one of these tools, you can easily rewrite the RESTful urls to be handled by your default.aspx page (or whatever handler you choose to use).
If you can allow the restriction of only IIS 7.0 and above you could use URL Rewrite http://www.iis.net/download/URLRewrite to do that pretty easily.
Can I ask why is it that you need to support IIS 5+? That is an 11 year old technology that hopefully people will move out of those platforms in favor of more recent versions. Also keep in mind support for some of those platforms is ending pretty soon.
If the concern is developers running Windows XP I would point out that IIS Express includes version 7.5+ functionality and is available for all platforms Windows XP and above.
I think this will be difficult to do because IIS 5 will not let you handle non ASP.NET file extensions without some additional configuration in IIS. That means you are limited to URLs ending in .aspx etc. To handle URLs like those in your examples you need to map ASP.NET to handle all URLs in IIS, implement some type of URL rewriting, or introduce some kind of hacky 404 redirection.
Once you have the correct mapping in place you can wire up an IHttpHandler, but you will have to parse the incoming request yourself to work out which is /MyService/MyMethod1/ and which is for /MyService/MyMethod2/. If your methods are simple then it is easy to do this with a regular expression.
You should start with a simple handler like this one.
I need a way to acccess files on a fileshare from a different domain from my own? for example, I have here is an application that exists on a sever in Domain1 and this application needs to retrieve files from a server on Domain2.
Any ideas...
Does this help you in the right direction? I assume it's what your asking...
Map a Network Drive From Code for Cross-Domain File Copy.
The CodeProject link given on the site also gives the source code for downloading.
I recently had a similar issue and executing
net use \\machine.otherdomain myusername /USER:password
as part of the user's network logon was a solution for us.
This is obviously not perfect but for our environment it was sufficient.
I am putting together a retail site and want to know what the 'correct' way to implement an SSL in a .Net project is? I realise that that is a bit open ended but i find the MS documentation on the matter a little confusing. I want the whole site to use SSL, and I have also read that the cookie used must also have certain switches turned on in order that it not be transmitted, even whilst using an ssl, and sebsequently can be read in plain text.
I'm using forms authentication and have set in my web.config file for the site to 'requireSSL' how do I 'force' each page to use the connection etc.?
I am on a shared host but their end is configured to use SSL but I have to force my pages to use it etc...
So configured my web.config file to use SSL in conjunction to forms authentication, paid and installed my SSL on my host, what's next? Its all windows technology.
Is your host IIS, and if so you can force SSL within IIS:
http://www.sslshopper.com/article-forcing-ssl-in-iis.html
Now once you have that, you can just build your app as normal.
This will force SSL on every page.
How can I either create a new website or add a host header to an existing IIS 7 server from code?
I have looked and have not been able to find a working example?
One solution would be to create a custom HttpModule that does the work for you, however it does require you to be have a DNS that supports wildcards (*). If your DNS does not support that, you might look into managing your own DNS.
That said, here's a good post on creating an HttpModule that parses the "subdomain" passed in and forwards the traffic to the appropriate spot. He's using a search mechanism [to locate content with keywords matching the subdomain], but it can be modified for you own needs.
http://codebetter.com/blogs/brendan.tompkins/archive/2006/06/27/146875.aspx
[EDIT]
Another solution would be to find a DNS provider that offers a programmable DNS service, perhaps through a web service. You would then programatically add a subdomain to that DNS when needed from your application. That's a super simplified explanation, and doesn't take into account your business needs. Personally I prefer the HttpModule option for adding subdomains within an application as it requires less modification of the server(s) involved.
What version of .Net are you using?
If you are using .Net 3.0 or 3.5, and if you only need to configure IIS7 (not 6 or 5), check out the Microsoft.Web.Administration namespace -- it should have everything you need.
If you are using an older version of .net, have a look at WMI.
I don't have any WMI code for IIS 7 (we have a setup for an intranet application, but it uses IIS 6-compatible WMI). But, here's a link to a tool you can use for figuring out the WMI stuff: http://www.microsoft.com/downloads/details.aspx?familyid=2cc30a64-ea15-4661-8da4-55bbc145c30e&displaylang=en It will actually generate c# (or vb.net) code for manipulating WMI. For IIS 7, I think that the root WMI namespace is root\WebAdministration.
Also, have a look at this link, it might help Get to Know the IIS 7.0 WMI Provider Using CIM Studio