Internet Information Service(IIS) Manager issue - c#

I am publishing my site in IIS and my WebDav folder is configured in other PC of IIS.
I want to get that website name using some c# code.
How can I get the site name of my WebDav folder in my published web site (ex: Default Web Site) using c# code?

So you want to figure out what Site Name(s) exist on an IIS instance from the IP address?
take a look at this artice:
http://cstruter.com/blog/306
and where you see this line of code:
foreach (Website site in GetSites("IIS://localhost/W3SVC"))
put the IP address where you see localhost. if the ip address was 123.123.123.123 then it would look like this:
foreach (Website site in GetSites("IIS://123.123.123.123/W3SVC"))
You will need adequate permissions to enumerate the Sites! (see the comments below the article for some notes on this)

Related

Typical 404 - File or directory not found?

I read a number of Google and Stackoverflow posts without success.
My c# application sends out emails with a hyperlink in. The hyperlink address is:
http:\\41.xx.xx.x\Documents\logoColourBG.jpg
When clicking the hyperlink, I get:
404 - File or directory not found.
The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.
The subfolder Documents is shared and users IUSR and IIS_IUSRS do have access to it.
If you are trying to access the file directly over the network in windows explorer or so you should try something like this :
\\41.xx.xx.x\Documents\logoColourBG.jpg
But if you are trying to access it from the browser your request will be handled by IIS or another web server that is installed and configured on the machine.
Then you should set the folder's permissions and sharing options to default and then create a virtual directory like it is explained in here.

Website visitor location in ASP.NET

My ASP.NET website needs to know the city and country of the visiting user. I have tried following code:
string ip = HttpContext.Current.Request.UserHostAddress.ToString();
And then making a web request to http://api.hostip.info/get_html.php?ip=ip
This method returns me correct user location in some cases, but when user's ISP has hosted server in other country or city, then instead of giving me user's current city (from where he is browsing the website) it gives me the server hosted location.
How can I get the user's location regardless of where his ISP has hosted the server? Like Google does in Google Maps (where browser asks for permission to share location). Or any other better way?
The answer to your problems
See msdn code sample

publishing asp.net application to the internet

i have a web app that runs locally on our network. the way users access it is by going to myserver:80/site/default.aspx
i reconfigured the settings to display the website to the internet.
the way i am accessing it now is:
ipaddress/site/default.aspx
and getting the following error:
Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /site/default.aspx
so it seems as if it does see the site, but the site does not want to grant access?
what am i doing wrong?
edit if the consensus is that it doesnt actually see the webpage. then again i would like to know what i am doing wrong
You need to edit the host header bindings in IIS for your website.
If you are really on IIS 5.1 (which ONLY shipped with Windows XP Pro) then do the following:
Open your IIS Manager (go to start > run > inetmgr).
Expand the computer name.
Expand websites.
Right click on the site name
Go to the Website tab
Click on the Advanced button
In the "multiple identities for this web site" click the Add button
Set the IP address. Leave the Host Header Value blank
Click Ok
At this point there should be 2 identities listed. One that maps the DNS name to the IP address and another that only has the IP address.
IF for some reason it warns you about duplicate bindings, go to the other sites and remove any that tie the IP address to a blank host header. Then come back to this site and set up the blank configuration.
When moving from Visual Studio's built-in web server to IIS, often you need to simply remove the top level directory form the URL:
ipaddress/default.aspx
or simply
ipaddress
if default.aspx really is a default.
In normal case if you are hosting your site in IIS and if you are having your IP fix you can also browse your website through your local ip in your network by address by keeping your 'ipaddress' in place of 'localhost'. Now if you wants to access it from your global ip you need to add binding to the IIS and then it will respond to all the requests.
So in your particular case you need to add binding with your IP (check it from whatismyip.com). Go to IIS -> Sites -> Default Web Site. On right hand side column you will get bindings. Add new binding in it.

Tree View Directory Browser in Asp.net

I am using a Tree View Directory browser in my application. I am using
DirectoryInfo.GetDirectories()
DirectoryInfo.Getfiles()
My requirement is that I need to browse the server folders from client with this. I am able to access shared drives also from the same machine. I hosted the site in IIS6 in a virtual directory. When I try to access the shared drive from the client I dont find it. Do we have to do something in IIS? I tried giving IdentityImpersonate="true" but still getting same problem.
This is a double hop problem. The IIS server would have to do delegation to move your credentials across 2 hops, (your machine to IIS - IIS to file share). Configuring delegation is a tricky process, but I haven't tried in a while, maybe the diagnostics have improved. Normally you follow the delegation instructions and still get access denied.
The easier solution is to use explicit credentials to go from IIS to the file share. The down side to this is that you have to specify username and password of a windows account somewhere in your web.config or source code.

How can I create a subdomain in asp.net?

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.

Categories

Resources