Classic ASP + IIS 7 Writing a file to a network drive - iis

I have Classic ASP 2 websites on an Windows 2008 IIS 7 install. website1.com and website2.com. Both are serving the same website from one folder: C:\Webs\website\
website1.com has been in operation for 6 years and in the app it can write files to a network share; \wdc\SharedFiles\assets\docs\
All the proper permissions are set as it has been reading and writing files for years.
I recently added website2.com. The website is serving from the same diretory. I need it to be able to write to that same share. The problem is, website2.com gets "Write to file failed." and "Permission Denied" errors.
How is this possible?
I even mocked up a simple test. Same error.:
Dim fso, objFile
Set fso=Server.CreateObject("Scripting.FileSystemObject")
Set objFile=fso.CreateTextFile("\\wdc\SharedFiles\assets\docs\test.txt")
objFile.WriteLine("hello this is test")
objFile.Close
Set objFile=Nothing
Set fso=Nothing
Any ideas? I am pulling my hair out.

I figured this out on my own. So others can benefit, here it is:
In IIS go to the website (website2.com) node, then select "Authentication".
Make sure "Anonymous Authentication" is enabled and set it to a user.
Then with the Explorer give that user read-and-write access to the share.

Not sure if this will make a difference. The only difference in my code, really, is that I'm using server.mapPath to specify path.
path = Server.MapPath ("\")
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.CreateTextFile(path & "\" & txtFileName, 2) '2 = for Writing
f.Write(txtFileContents)
f.close
set f=nothing

Related

Run-time error '52': Bad file name or number (SharePoint link vs Windows path)

When I try to assign a SharePoint link to flnameI I get a "Run-time error '52': Bad file name or number" on the yellow highlighte line in the image I attached
e.g. when flnameI = https://cogsandwheels.sharepoint.com/sites/accountsdept/test.xlsx
But when flnameI is equal to a windows explorer path like C:\Users\John.test.xlsx I get no issues.
How do I cater for a SharePoint link in this example?
flnameI = ActiveWorkbook.Path + "\" + folder + "\" + txtAgentFile.value
If Len(Dir(flnameI)) = 0 Then
MsgBox ("FATAL ERROR - file not found - " + flnameI)
End
End If
You are attempting to open a file from a SharePoint Online location as compared to a local file system. When you're opening the local path, Windows automatically authenticate you in the background and it "just works". When you're trying to go after cloud hosted content such as this document in SharePoint Online, you will firstly need to authenticate against M365 and secondly use something like REST, CSOM or Graph APIs to get the file. If you choose REST (since its the future anyway), Sunil wrote a great article about accessing SharePoint REST calls using OAuth here:
https://www.advaiya.com/access-sharepoint-rest-api-using-oauth/
The SharePoint REST APIs are documented here by Microsoft:
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-sharepoint-rest-endpoints
Lastly, if your taste prefers Graph (which to be fair is just an API wrapper for REST calls anyway), then Microsoft has documented that for you here:
https://learn.microsoft.com/en-us/graph/api/resources/sharepoint?view=graph-rest-1.0

how do I fix HTTP Error 401.3 - Unauthorized?

So I've come across a problem, what I am trying to do is "Check if the python file is ready to execute" as verbatim by my CS professor. So here I what I have done so far:
-Enabled Directory Browsing
-Added a new Script Map
-Linked the executable to the python executable of my python project
-Changed its directory to a new folder (as instructed)
-Created a New Python File with this code in it:
print("Content-Tytpe: text/html\n");
number1 = 1
while number < 10:
print("Hello Python World! <br>");
number = number+1
-and finally clicked on "Browse .80"
I clicked on "test.py" (the python file) and this showed up:
I researched a couple of fixes in this site and among others and this is what I have tried:
-Checked the permissions in the folder and made added a new permission for Everyone with Full Control Access
-Checked Authentication and Anonymous Authentication and set it to Application Pool Identity, both on the Desktop and the Default Website
-I even went to go as far as resetting my PC to check if some other third party application is affecting it
I am really at the end of my rope here so any help would be greatly appreciated.
Try to refer to the steps below.
In IIS, select your site -> Double click on Authentication -> Select Anonymous authentication-> Right-click on it and select Edit option.
Select a Specific user option. Set IUSR, click OK.
Go to the site folder-> open its properties-> go to Security tab-> Make sure IIS_USRS has Read & execute, List folder contents, Read permissions.
After that try to visit the page again.
If the issue persists, try to check whether you are able to visit any HTML file in that folder or not.

Permission denied when creating text file in asp

I have the following code:
<%
dim deviceid
dim fso
dim outFile
deviceid=Request.QueryString("deviceid")
If deviceid<>"" Then
Response.Write("Hello " & deviceid & "!<br>")
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set outFile = fso.CreateTextFile("C:\Users\Victor\Desktop\respTank.txt")
outFile.WriteLine("Hello World!")
outFile.close
set outFile = nothing
set fso = nothing
End If
%>
I get the following error:
Microsoft VBScript runtime error '800a0046'
Permission denied
I gave all permissions to IIS_IUSRS but it didn't help. Can anyone help me here?
It sounds like the ApplicationPoolIdentity is not the user context being used by the Web Application.
Depending on the IIS Version, you want to check (using the Manager)
IIS 4-6
Web Site / Application Properties -> Document Security
IIS 7+
Web Site / Application -> Authentication
and check the Anonymous Account which can be set differently to the ApplicationPoolIdentity.
Based on this value apply the permissions (at least Modify) to the folder C:\Users\Victor\Desktop\ and you are good to go.
I just had the same thing happening on a delete file, have you tried removing the parenthesis?
Set outFile = fso.CreateTextFile("C:\Users\Victor\Desktop\respTank.txt")
to
Set outFile = fso.CreateTextFile "C:\Users\Victor\Desktop\respTank.txt"

IIS6 bat file - Home Directory

How do I get the Root/Home Directory of a website in IIS6 using a batch file??
My Scenario:
I am creating a tool to summarise and report of sites in IIS. I am using batch files and running iisweb /query to get all the sites then looping over the results and using iisvdir /query "Website Name" to get the virtual directories.
However it has to be backwards compatible with IIS6 and I am having trouble getting the Home Directory of the site.
I don't think you can do this directly from a batch file, but you should be able to do it from a vbscript which you can call from a batch file.
The trick is to use the IIS WMI provider which gives you access to the IIS metabase. For example, the script below should echo the name and path of every virtual directory on the local server.
set provider = GetObject("winmgmts://localhost/root/MicrosoftIISv2")
set results = provider.ExecQuery("SELECT Name,Path from IISWebVirtualDirSetting")
for each item in results
WScript.Echo item.Name
WScript.Echo item.Path
next
If you saved this script as iispaths.vbs (just as an example), you could then call it from a batch file with:
cscript //nologo iispaths.vbs
Unfortunately I don't have access to a machine with IIS6, so I am unable to test this at the moment, but if you have any problems getting it to work, feel free to let me know in the comments and I'll do my best to fix the issue.
I don't have a IIS6 server, however, through some searching, I found that:
IIS6 uses %SystemRoot%\system32\inetsrv\MetaBase.xml and %SystemRoot%\system32\inetsrv\MBSchema.xml for storing configuration (The IIS Metabase (IIS 6.0));
If your server isn't changing home-directories too often, those xml should be updated;
using a command line parser (like xmlstartlet), you can extract Path property from IIsWebVirtualDir node (according Metabase Structure), using XPath.
With xmlstartlet, a command like below, would output root path:
xml sel -t -v "//IIsWebVirtualDir[#Location='/LM/W3SVC/1/ROOT']/#Path" "%SystemRoot%\system32\inetsrv\MetaBase.xml"
Maybe schema needs to be corrected.
This can be a command line approach. I can't test it as I don't have any IIS6 server neither I can get any MetaBase.xml sample.

How to debug ASP permission problems with WScript.Shell object?

I have to run command line operation from some legacy ASP application.
Here is my code:
<%
cmd = "%comspec% /c echo Hello"
set wsh = CreateObject("WScript.Shell")
ireturn = wsh.Run(cmd, 0, true)
set wsh = nothing
%>
And here is result I am receiving:
Microsoft VBScript runtime error
'800a0046'
Permission denied
/test.asp, line 6
Do you have any idea how to make IIS6 to run this code?
Note: Of course I don't have to run echo command but I want to exclude any additional causes of the problem.
Update: I tried most things tomalaks mention however nothing helped. Maybe I can alter question a little. How can I debug this problem?
ASP usually is denied access to anything potentially dangerous, such as cmd.exe. Check file permissions on cmd.exe to see if that is true for you (I suppose it is).
If you really must use cmd.exe to do part of the page processing, either change file permissions on cmd.exe (not recommended for an Internet-facing web-server), or make sure that the ASP page runs credentials that are not denied access to that file.
To achieve this, use the IIS management console to remove "anonymous access" to the ASP page and use Windows-integrated authentication instead (if feasible), or leave "anonymous access" on and enter a fixed set of credentials that should be used instead of the default "IUSR_...".
Alternatively, if you use cmd.exe just to start a program that outputs something to STDOUT, you can try starting the program directly, without wrapping it in a cmd.exe call. Again, the user the ASP page runs under needs access to that program's executable.

Resources