My InstallShield installer needs to install a file in the IIS Default Web Site's Home Directory, and set it to the default web page.
Unfortunately, in our environments, I can't assume that the home directory is C:\Inetpub\wwwroot, but I need to find out what it is.
Any idea on how I can do this with a script? We need to support XP, 2003 and 2008.
Found it - it's dead simple:
Dim objIIsWebService
Set objIIsWebService = GetObject("IIS://localhost/W3SVC/1/ROOT")
wscript.echo objIIsWebService.Path
I knew there had to be an easy way!
You can use a script to enumerate the IIS Web Sites and query them for information.
Something like
SET objWebService = GetObject( "IIS://" & strServer & "/W3SVC" )
FOR EACH objWebServer IN objWebService
objWebService.SomeProperty
...
But I think this belongs on Server Fault.
Related
Did anyone observed or dealt with the following issue. I have couple web server (Dev, QA, Staging) all running Windows 2003, IIS 6.
Recently applied an update which uses the following lines of code:
sLogPath = Server.MapPath("../Templates/" & strFileName)
set fs = Server.CreateObject("Scripting.FileSystemObject")
If fs.FileExists(sLogPath) Then
That works fine on all dev systems but as soon as we moved it to QA I am getting an error:
The '..' characters are not allowed in the Path parameter for the MapPath method.
Line number xxx
Line number is to this line
sLogPath = Server.MapPath("../Templates/" & strFileName)
I tried replacing Server.MapPath("../Templates/") with Server.MapPath("/Templates/") but that gave me the root of IIS service (C:\InetPub\wwwroot) not the root of my sites. If I attempt to do Server.MapPath(strFileName) I am getting once again wrong path to the file because sites are not in IIS root but elsewhere on the drive.
Any ideas how this can be fixed?
The issue is you haven't got Enable parent paths enabled in the ASP application configuration.
Without it you are not permitted to use .. directory traversing in ASP functions.
For more information see Enable Parent Paths Is Disabled by Default in IIS 6.0
On a side note:
I tend to avoid the need for Parent Paths simply by configuring websites as separate web site instances in IIS rather than using %SystemDrive%\inetpub\wwwroot which is where the Default Website instance resides.
Doing this means that code like Server.MapPath("/") will be valid and point to the root of your site not the Default Web Site instance root.
In my website I save images to a folder(Photos) in code-behind by calling
ImageUploadControl.PostedFile.SaveAs(HttpContext.Current.Server.MapPath("~/Photos/" + Name + ext));
which throws an error 'Access not allowed' in medium trust.
Any alternate to save images in medium trust? The folder needs to be publicly accessible as clients access these images without any authentication, so I cannot save it in App_Data(one fix to this problem)
*Website is hosted on hostgator shared plan. There is a limitation to how much I can ask for server configurations.
EDIT:
Yes its a access issue, as resolving the ~ tilda, virtual paths is not allowed. I hope anyone has a workaround for this problem.
Given you're using a native .NET control, I think it's more due to file system permissions than the trust of the environment. If you were using a 3rd party control I'd say then it's a trust issue.
Having a quick look at Hostgator they use cPanel, from there there's the file manager section, and in here if you go and select the 'Photos' folder and select "Change Permissions", here make sure the folder has write access from the application.
Edit
Support article here for setting *nix permissions:
https://support.hostgator.com/articles/cpanel/how-to-change-permissions-chmod-of-a-file
And:
https://support.hostgator.com/articles/specialized-help/technical/my-script-needs-to-use-777-permissions
OK, as it's a path issue:
https://support.hostgator.com/articles/hosting-guide/lets-get-started/server-path-absolute-path
Is it running ASP.NET on a *nix box? Or is it running on a Windows Server and IIS?
Also, I think you may need to revise your code in this instance:
string pathRoot = HttpContext.Current.Server.MapPath("~/Photos/");
ImageUploadControl.PostedFile.SaveAs(pathRoot + "/" + Name + ext);
It looks like your original code is trying to use mapPath with the non-existing file path included.
This may work if you must have it one line:
ImageUploadControl.PostedFile.SaveAs(HttpContext.Current.Server.MapPath("~/Photos/") + Name + ext);
I am a noob. I am learning to develop and deploy small websites on the IIS server. Now i have the following confusion :
I think procedure to 'add' a website to the IIS server starts from adding a new virtual directory or adding a new website in the inetmgr. Please correct me if i am wrong. I also think that once we have done this .. it is mandatory to add the source of the project to the inetpub/wwwroot folder. Am i correct ? Is it always necessary to do so ? I am worried because in that case how can we run multiple websites ? Also .. say i have added a virtual directory to the inetmgr ... now what do i do to run my website ... i am trying but getting "Directory Listing Disabled" written on the browser once i type http:\localhost....\Default.aspx
No, the source does not need to be added to the Inetpub folder.
You can simply add a new virtual directory pointing to the location of the site.
(Make sure the selected location is the folder containing your Default.aspx page)
If all other settings are correct, you should be able to hit the site at
http://machineName/virtualDirectoryName/
For this address to work, make sure you are allowing default documents, you may have to add "Default.aspx" to the list depending on your IIS version.
I have a Classic ASP website which we have moved from IIS 6 to Win2k8 and IIS 7. Within the website folder structure, is a Virtual Directory called Products containing JPGs that are physically stored elsewhere on the same server.
Within a web browser, any of the Product JPGs display correctly on the page. E.g. http://www.MySite.com/images/poducts/widget.jpg works a treat.
However, this folder is unavailable when trying to access it in ASP code, using the FileSystemObject - all other files/folders are there except the Virtual Directory. Here is an example ASP code snippet:
Set objFSO = Server.CreateObject( "Scripting.FileSystemObject" )
Set objBaseFolder = objFSO.GetFolder( Server.Mappath( "../../Images" ) )
For Each objFolder In objBaseFolder.SubFolders
Response.Write( objFolder.Name & "<br>" )
Next
Set objFolder = Nothing
Set objBaseFolder = Nothing
Set objFSO = Nothing
Additionally, Persit's ASPJpeg Com Object has no problem opening and saving JPG files to/from this Virtual Directory from ASP code.
In IIS7, the website has an Application Pool, and I've tried all manner settings for its identity to no avail. I have also tried applying various security settings (IUSR_, Network Service, et al) to the physical folder that the Virtual Directory points to - even granting full control to "Everyone" at one point.
It really seems like the ASP process does not have permission to Virtual Directories. If anyone has and idea on how to solve this problem then I'd be most greatful.
Using FileSystemObject to do this is never going to work because it only works on the physical file system. It does not know about or understand virtual directories - this aspect of your site is managed entirely by IIS.
It is not a question of permissions it is a question of the directory not physically being there so browsing the physical file system will never see it
IIS manages virtual directories:
Navigating to an image in your browser works because IIS automatically maps the virtual path to the appropriate physical path.
Using AspJpeg works most likely because it uses calls to Server.MapPath to resolve the given path into a physical path
This cannot be an issue of permissions since you stated yourself that AspJpeg can read and write to the virtual directory fine plus you can access it through your browser fine.
I vaguely remember having a problem like that and the culprit was Server.Mappath. To solve it I needed to map to a file inside the folder and then remove the file part
Server.Mappath( "../../Images/dummy.gif")
the "../" notation is not always allowed for security reasons. If you have access to IIS see if it is enabled or disabled.
I'm currently in the process of upgrading old II6 automation scripts that use the IISVdir tool to create/modify/update apps and virtual directories, and replacing them with AppCmd for IIS7.
The IIS6, "IISVDir" commands reference paths in that are from the metabase, eg, /W3SVC/1/ROOT/MyApp - where 1 is ID of "Default Web Site". The command doesn't actually require the display name of the site to make changes to it.
This works well, since on a different language OS, the "Default Web Site" site name could be named, for example, "既定の Web サイト" or anything else for that matter. But this flexibility is lost if AppCmd can only reference "Default Web Site" via its name, and not a language-neutral identifier.
So, how can I script AppCmd to refer to sites, vdirs and apps using language neutral identifiers to reference the "Default App Site"?
Perhaps I need to start creating my own site instead, from the start, and name it something else specific, and stop using "Default Web Site" as the root?
(Disclosure: I only have a IIS7-English machine that I am working on currently, but I have both IIS6-English and IIS6-Japanese machines for testing my old scripts - so perhaps it really is just "Default Web Site" still on IIS7-Japanese?)
The APPCMD tool appears only work with the site name (mostly). I asked a similar question on Server Fault a while back about exactly the same issue:
How do I reference a site by ID using IIS7 APPCMD? (ServerFault.com)
If you want to start working with the site by ID then you need to do this programmatically, for example:
int iisNumber = 1; // The default website
using (ServerManager serverManager = new ServerManager())
{
var site = serverManager.Sites
.Where(s => s.Id == iisNumber)
.SingleOrDefault();
if(site != null)
{
site.Stop();
// Do stuff to site...
site.Start();
}
serverManager.CommitChanges();
}