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
Related
I've got this scenario: I want to build a website to a friend só he can manager his business. I want to do it like it is going to be online, using C# MVC. The thing is that only my friend will use the system, on localhost:/something...
My question is: if I put the files of my app on Apache, installed in my friends computer, will he be able to access the web site thru localhost:/mysite...?
I think for your use case ASP .net Core makes perfect sense. Have a look at the these articles and sample
https://docs.asp.net/en/latest/intro.html
https://github.com/aspnet/MusicStore
Easy to run/deploy and don't need IIS Install either.
https://sourceforge.net/projects/mod-aspdotnet/
mod_aspdotnet is a loadable Apache 2 module for serving ASP.NET
content using the Microsoft's ASP.NET hosting and .NET runtime within
the Apache HTTP Server process. Non-Windows users should look at mono
(mod_mono) for an alternate implementation.
We have an application in Access for UI and MS Sql server as Database server. We now decided to build a new application in web application for UI. This web application is only used by the employees who work for the company. But later we decided to host this web application on outside server. So the user (from this company only.) can able to login anywhere in the world. First I thought creating the web application using 'windows' authentication thinking we may be using it as an intranet web application. But now my manager asked me to use both 'Forms' and as well as 'Windows' for using this application and this web application will be hosted on outside server. I really don't catch his point of using both types of authentication.
Please help me is there any ways to use both authentication methods and please also suggest me why we might need to use both authentication methods. If so could you please help me with some instructions of using the both authentication types. Thank you so much for taking time to read and understand my question and helping me in this regard.
#Will explained in his comment as to why both forms of authentication is preferred. The following article shows one way to implement what you need.
You may also want to check the following article to better understand how Windows Authentication works.
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 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
Is there a proper .NET solution for providing persistent server sessions over multiple domains?
i.e. If a user of the site logs in under www.site1.com, they will also then be logged in under www.site2.com
Security is an issue with the program we are working on...
Thanks!
Does it need to be in the session or are you looking for a single signon solution. If the latter take a look at something along the lines of ADFS
http://en.m.wikipedia.org/wiki/Active_Directory_Federation_Services?wasRedirected=true
You may want to start here instead of hacking into the ASPState database(possible, but I don't recommend it): http://www.codeproject.com/KB/session/sharedsession.aspx
Basically you set the AppDomain to be the same for both www.site1.com & www.site2.com using reflection.
You also may need to AppPath as well, we needed to, but our setup was slightly different than what you have. We added:
FieldInfo appDomainInfo = typeof(HttpRuntime).GetField("_appDomainId", BindingFlags.Instance | BindingFlags.NonPublic);
appDomainInfo.SetValue(theRuntime, "/LM/W3SVC/1/ROOT/A_Website_Name_Here");
The word 'session' can be a little confusing in ASP.NET.
If you are talking about security (authentication and authorization), you are probably looking for a Single Sign-On solution. In other words, when a user logs into one site they won't be prompted to log into another related site. Take a look at Windows Identity Foundation, OAuth, Jasig CAS. CAS is my preferred solution (I'm a developer on the .NET client), but the server is written in Java and you'll need some expertise with Java to get it configured the way you want.
In ASP.NET, Session state is a completely separate component from authentication and authorization (although it can depend on the result of the authentication step). If you are trying to share information between the 2 sites (i.e., shopping cart contents), you can either configure both domains to use the same database as a Session provider (google aspnet_regsql -ssadd) or you can just store the data in a database that is accessible by both.
For more info on why I emphasize the distinction, check this out: http://www.codeproject.com/KB/aspnet/ASPDOTNETPageLifecycle.aspx
Good luck.
Try using the canonical hostname URL Rewrite feature of the IIS 7.5 Url Rewrite 2 Module: Download
(This answer relies on both URL have hostheader entries for the same web application)