IIS - Start In Directory - asp-classic

I am setting up a new test server for an application created by a previous developer. Please see the code below:
strLines = Split(strData, vbCrLf)
lngLinesRead = UBound(strLines)
intFile = FreeFile
Open "log.txt"For Append As #intFile
Print #intFile, Now & " ***************** Start of import. User: " & strUser & " on: " & strTerminal & " ******************** "
Close #intFile
This code is creating a log file in the following location: "c:\windows\syswow64\isvr\log.txt. On the live server (and existing test server) it is written to: c:\iispages\app\log.txt. How do you specify the relative path? Is this done in IIS.
When creating a scheduled task; there is a 'start in' option where you can specify the starting directory. Is there something similar in IIS?

The file is going to be written into the "current folder" of the web server. This will be the folder where the ASP page is executed from. The two paths you posted represent the active folders the different web servers were using when those files were written. You can specify a deeper path in the Open statement:
Open "c:\windows\syswow64\isvr\SUBFOLDER\SUBFOLDER\log.txtFor Append As #intFile
But since this is being managed by IIS, it must be a folder that IIS service is allowed to write to. If you need to write to a folder outside the scope of the web service you can edit the folder permissions in windows to give permission.

Related

Save file to a folder in the website in medium trust in ASP.NET

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);

ASP - Permission denied

before I start, I'm a PHP programmer, not an ASP programmer, but at my job, they use ASP and I don't have acces to the server, but I can contact the person in charge.
I'm working on an ASP function for work and I alway hit this "Permission denied" error. I made some search and I found that the account need permission to run the script. It's maybe just me, but I don't understand that ASP check the user before run a script, I mean, it's a public website, obviously they will not have acces if I don't.
Can I change the file so anyone can run it ?
EDIT :
My script is trying to edit a file on the server
dim fs,f
set fs=Server.CreateObject("Scripting.FileSystemObject")
set f=fs.OpenTextFile(Server.MapPath("test.txt"),8,true)
f.WriteLine("This text will be added to the end of file")
f.Close
set f=Nothing
set fs=Nothing
Thanks
The account that IIS uses (probably iusr) needs to have read/write permissions on the target folder. I would recommend using a temp folder (anything other than the website's root folder)
By default, the account will have no permissions. That's simply basic security. You need to have whoever administers that machine give permissions on an appropriate location.

file path to the server classic asp

<%
virtPath = "\\mnbv00ww7044832\central engineer\OH\OSP Engineering\ATHN\2011"
''#virtPath = "C:\central engineer\OH\OSP Engineering\ATHN\2011"
dim fs
set fs=Server.CreateObject("Scripting.FileSystemObject")
if fs.FolderExists(virtPath) then
response.write(virtPath & " exits !!!")
else
response.write(virtPath & "does not exist")
end if
set fs=nothing
%>
According to this code the folder exists when i give path as C:... , but it shows that the folder does not exist when i try to access it through the computer name. I tried almost everything that i could come up with, but for some reason i cannot find the solution. basically i need to access a folder on a different computer.
Thanks
Nik
First its not clear that you understand that you cannot simply substitute the "\mnbv00ww7044832" for "c:". However lets assume you have actually created a network file share with the name "central engineer" on the "central engineer" folder.
You need to ensure that the user security token being used to access the share has not only access to the folder but also has access to the share.

appcmd created site ignoring asp.net web.config file with iis 7

If I make a site manually via the inetmgr app (IIS 7) and give it a site name and physical location (as well as changing its app pool to .net 4) it all runs fine and picks up the web.config file.
However if I set up the same site on the command line using appcmd it for some reason ignores the web.config file, the inetmgr shows the site working and the files being there, but under "Configuration Editor" there are no entries there from the web.config file.
The command line app cmd is run from a build script, but the method to do this is below:
def create_web_site(site_name, site_location, site_port)
delete_command = "#{$file["appcmd"]} delete site #{site_name}"
result = system delete_command
puts "Failed to delete site on IIS: #{$?}" unless result
add_command = "#{$file["appcmd"]} add site /name:#{site_name} /bindings:http/*:#{site_port}: /physicalPath:#{site_location}"
result = system add_command
raise "Failed to add site on IIS: #{$?}" unless result
set_app_pool_command = "#{$file["appcmd"]} set app #{site_name}/ /applicationPool:\"ASP.NET v4.0\""
result = system set_app_pool_command
raise "Failed to bind site to .net 4 app pool on IIS: #{$?}" unless result
start_site_command = "#{$file["appcmd"]} start site #{site_name}"
result = system start_site_command
raise "Failed to start site on IIS: #{$?}" unless result
end
You don't really need to know rake/ruby to see it is running appcmd and deleting a site if it exists, then adding the new one, using the .net 4 app pool then starting the site. This all works fine and I can see the 2 sites which are identical as far as I can tell (other than the one I am manually creating via the GUI has a different port to the other to stop conflicts).
Is there something im missing from appcmd which the GUI does for you when setting up sites?
After tinkering around the issue is down to the slashes between folders being incorrect for IIS. It all appears to work but wont pick anything up, so where my site directory was something like:
c:/some_folder/some_site
in my script I had to swap them to:
c:\some_folder\some_site
Everything worked fine, however as the "\" character usually signifies a skipping or ignoring on the following character I just did it as a string replace on the first string rather than entering it in as the correct way to begin with.

ASP Classic can not access Virtual Directory using FileSystemObject on IIS 7

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.

Resources