How can I create a subdomain in an asp.net C# application? I am working with an asp.net portal. In that portal I need to be able to create the subdomain at runtime. The ftp for that subdomain also needs to be the same as the main domain ftp.
There are a handful of working parts here. It sounds like the requirement is that this all happen at runtime. I am sure a lot of web hosting providers are deep into these sets of problems and likely have custom solutions.
DNS: you'll need to have an API open at the DNS host. If it's a LAN environment, you'll have to check your DNS provider on whether they have APIs exposed. (i.e. Windows Server or whatever your network operating system is). If this is a public facing site that needs to be accessed via the internet, you'll have to get those APIs from the DNS registrar. Are the subdomains to be permanent?
IIS: You'll have to setup wildcard mapping, (i.e. *.mydomain.net). When an HTTP request comes in, logic within the ASP.NET page can determine the subdomain that you're working with. You could extract the subdomain, perform a lookup on that subdomain to get more information (CustomerID, names, valid visitor IP address ranges, whathaveyou).
FTP: if you require secure logins for that subdomain, you'd have to have created AD or local machine accounts for those users. If you want anonymous access, that's OK too. There are some scripting options that you'll have to look at to have that FTP folder setup as well. That is assuming you're using IIS's FTP module. If you are using a 3rd party FTP application, that complicates the scenario even further. Their APIs would have to be investigated.
Active Directory: If you are requiring secure access for each subdomain, you'll have to create AD users and/or groups. You can certainly script the creation of users into groups. Perhaps the users will be local to your web server. That doesn't scale well if you want to add another web server, but it's certainly do-able.
subdomain's are controlled by your dns settings. Beyond that I can't understand your question.
I think the best way is to have a wildcard DNS entry - i.e. *.domain.com that points to the domain. And then use a rewriting tool, like helicontech.com, to rewrite the 1st part of the subdomain to tell your app what you're looking at.
This would use regular expressions to pass the subdomain to your app:
RewriteCond Host: (mysub).domain.com
RewriteRule (.*) /$2?subdomain=$1 [I,L,U]
There are two halves to this:
A) Changing your DNS Settings:
This varies based on your host and whatnot. Contact them and ask if you can't figure it out.
B) Changing your host settings:
This varies based on your server. I assume you're using some version of IIS.
In IIS6, you can right click a web site, select the properties page, go to the web site tab, select advanced in web site identification, and start adding bindings (Generally you'll use default or the ip address for IP Address, 80 for TCP Port (unless SSL), and the site for the host header file (e.g. www.example.com or subdomain.example.com).
In IIS7, you right click on a website and select edit bindings, then click "Add". IIS7's add screen is pretty self explanatory.
I think he wants to created a subdomain from code, using an API probably that needs to be provided by his webhost folks. Like his own DNS manager app. If I interpreted your question wrong, then I guess you probably oughta reiterate a bit more.
Related
I'm working on a .NET Framework website that is only opened from a redirect command. Is it possible to do that only if I redirect from a certain website?
For example, if I have a personal blog and I want to redirect users to a certain site, that site would only open if the previous website is one I can whitelist or something like that.
If possible, I'd like to do it server side (the redirecting application is built in .NET Core 2.1)
Thanks a lot!
Technically, no. While you can use the Referer (historically mispelled) header, that header is not guaranteed to be present and can also be spoofed. In other words, if the client simply doesn't send the header, there's no way to know whether the user was redirected from your other site or not. Even if it is present, the client could have simply sent the header manually and completely bypassed your other site.
If the two sites are on the same domain or subdomains of the same domain, you can set a cookie at your other site that is then checked on the redirected site. However, the sites need to be able share cookies, which again, means same domain and both have data protections providers configured to utilize the same distributed store.
If you want to limit access the best and most fool-proof way is always going to be auth. Make them login at both points and you can ensure that no one can do anything you don't want them to do.
I'm trying to set up a payment system in my web applications.
So far, i've been instaling certificats, programming C#, but there is something in between that i don't understand.
I'm supposed to find a private key with the FindPrivateKey tool...(i found it, in \Microsoft\Crypto\RSA\MachineKeys without the FindPrivateKey tool)
And give the rigths to my AppPool user ( i'm just testing local so... i don't know) to use the key... i guess...
They suggested me these links :
http://msdn.microsoft.com/en-us/library/aa702621(v=vs.110).aspx
http://msdn.microsoft.com/en-us/library/ms732026.aspx
http://www.dotnetnoob.com/2011/01/how-to-give-iis-access-to-private-keys.html
http://benoit808.wordpress.com/2008/10/31/cryptographicexception-the-handle-is-invalid/
After reading them, i was even more confused.
What is FindPrivateKey tool ?
I'm i not supposed to be able to use certificats if i'm testing on localHost ?
What is FindPrivateKey tool?
In order for your web application to access the private key, it needs access to the file containing the private key. The point of the tool is to help you find the file so you can right-click on it and assign permissions to the service account associated with your web application. If you know where the file is then you don't need it.
I'm not supposed to be able to use certificates if I'm testing on local host?
Depends what the certificate is for.
If we are talking about the SSL certificate that is being used to secure your web site, the domain name of your site must match the subject of the certificate; https://localhost won't work. It has to have a proper domain name. You can work around this by assigning the domain name your loopback address via your hosts file, e.g.
127.0.0.1 www.TheNameOnMyCertificate.com
...after which you could access your (local) site using https://www.TheNameOnMyCertificate.com.
If we are talking about some other certificate, e.g. a client certificate that your application has to use in order to talk to a third party payment service, then that is totally different. In most cases you can use the certificate without any issue.
Hi Developers/Architects,
This is more of an Architectural question:
I have a web application. The application use ASP Membership API (froms authentication) for users/roles management.
We host a separate application for each of our clients. So basically each client has an Application Name in ASP Membership database. That client then create his roles/users according to his need.
The reason why we have same website, hosted on IIS for each client separately under client name's virtual directory, is because all of the clients have their separate Application Name (in terms of ASP Membership), and the underlying database is separate for each client as well.
so each client has a separate URL, e.g: http://mysite/client1. and then client1 has his own users, roles. The underlying application database used by application is clients individual.
The Web Application and the database schema is exactly same for all clients.
I can not take any decision regarding the database part. So i am not going to discuss that.
But i want to change the approach of hosting separate application for each client. I want to host one application for all clients:
this brings some questions:
Q1. how would i create these urls: http://mysite/client1, http://mysite/client2 (as i can not put names of all clients on the main login page, and then once user selects the client name, provides username/password .... i can not do that due to the nature of the business)*
Q2. I can not create single application (on IIS and on ASP Membership level) and then separate clients by roles, because all clients have roles within themselves, and plus, 2 or more clients can have a user by same name; so userX for client1 and userX for client2. theses users are different, but they happen to have same names.
* One solution to Q1 can be: that i create a new forwarder application, which is hosted for each client separately in IIS under client's virtual directory. And when client opens their url (e.g: http://mysiteforworder/client1) they are redirected to (http://mysite/Default.apsx?app=hjuk98jkio8) where (hjuk98jkio8) is a encrypted name of the client, that we use internally.
this would resolve Q1, but not Q2.
let me know what options do I have ...
Here's an idea I've used a few times before.
You can set up multiple Web Applications / Virtual Directories in IIS, e.g. /client1 and /client2, that point to the same physical web application path on disk. That way the code is still the same for all customers, all managed centrally, but there are different URLs for different customers.
Using WMI you can even script or automate creation/maintenance of the webapps/vdirs in IIS.
To determine which DB to connect to, or which app is running, you can look at the URL being accessed and use the first part of the path as a key into a configuration dictionary for that customer.
I'm writing a SaaS app in C#/ASP.NET, hosted with IIS7. I want to create a personalized subdomain for every customer that signs up, i.e. fred.mydomain.com, bob.mydomain.com, each of which will point to the same app, just with a different skin per customer.
How do I create these subdomains programmatically?
Use URL Rewrite for IIS7 to map all requests like user.mydomain.com (where user is not www, mail or other existing real subdomains) to mydomain.com/myapp?id=user Then in the script handle whatever theming you need.
You do not need to add rule for every user created. Just create one general rule to do so.
And, also, in your server DNS, you need to forward *.mydomain.com (where * is not www, mail or other existing real subdomains) to mydomain.com IP. This is pretty straight forward. You already have DNS records for existing subdomains. Just add *.mydomain.com and point to mydomain.com. This will do the DNS part of the trick. Other part is in the URL Rewrite
Realizing of course that someone already answered your question by telling you to do redirects, it seems the easier way might be to just grab the host server variable.
Setup IIS so that all incoming requests (regardless of the host
header) point to this one application. All sites have to either have a unique hostname or unique port in IIS, so you would set this up by:
Binding the site to the default port of 80.
Not providing anything in the Host Name field. This is also how the Default Website is setup by default when you first install IIS.
Figure out the static IP address of your server, and tell each new client that signs up to point the DNS for their domain to that IP. Or, if you will own the domain name, setup a catchall DNS entry: *.mydomain.com - points to the IP address of your server.
Within your application, check for the current
host header in order to provide a
different skin or master page.
This should grab the host header from within the code:
Request.ServerVariables["HTTP_HOST"]
From there you could test its value against a set of database values you have to determine which MasterPage/css stylesheet/etc you need to load based on that URL. Keep in mind if you do a catchall like this that you'll need to account for a URL mistyped that you therefore wouldn't have a skin to match to it.
I have a C# web service on our website and I only want to be able to call it locally where its hosted - restricting access from the outside world. Whats the easiest way to do this without a login form? We cannot restrict the web service directory per ip (because I don't believe its static)
Alternatively, you could also host them on a separate website, which you only bind to localhost (127.0.0.1)
PS: You should really get a static IP for your webserver. Or at least reserve an IP address for the server's mac address in your DHCP server configuration.
You can setup windows authentication on the web services and require the authentication be a local account to that machine. You'll have to modify your code calling it by providing network credentials, but that will prevent people from the outside calling it.
This article should explain how to do it.