How do I access a value from machine.config in classic asp? - asp-classic

How do I access a value from machine.config in classic asp?
I can't find the answer anywhere....
I don't even know how to begin to try to find a solution....

Use TextStream object.
Example:
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile(Server.MapPath("testread.txt"), 1)
Response.Write(f.ReadAll)
f.Close
Set f=Nothing
Set fs=Nothing
%>
https://www.w3schools.com/asp/asp_ref_textstream.asp

Related

Classic ASP FSO Permission Denied

I trying to get list of file via Classic ASP FSO companent.
But even I gave the root file permissions (IUSR_domain) from remote desktop, still I getting this error.
Microsoft VBScript runtime error '800a0046'
Permission denied
/default2.asp, line 28
<%
fs,fo,x
set fs=Server.CreateObject("Scripting.FileSystemObject")
set fo=fs.GetFolder("C:\inetpub\vhosts\xx.com\httpdocs\photo\other") <-- line 28
for each x in fo.files
%>
<div id="photos">
<div class="photo"><%Response.write(x.Name & "<br>")%></div>
</div>
<%next
set fo=nothing
set fs=nothing
%>
Try using Server.MapPath
for example:
downloadFileDirectory = Server.MapPath("\httpdocs\photo\other")
Set fs= CreateObject("Scripting.FileSystemObject")
If fs.FolderExists(downloadFileDirectory) Then
Set fo= fs.GetFolder(downloadFileDirectory)
for each x in fo.files
%>etc.
set IUSR_machinename and IWAM_machinename to have change permissions for the folder.

Read cookies value

I am converting a classic ASP page to ASP.NET Vb . I get a line of code Where reading value form cookies .Below is the line of code where value is checking . My problem is that how can i convert this line of code in ASP.NET VB . I am doing inline code for conversion
<%if request.Cookies("parker")("id") <> "" then%><input name="agreement_acceptance_box" type="checkbox" value="yes"><%end if%>
Thanks for your answer . Its really very important for me
I think the problem is to read an array from the cookie? You don't provide much 'context', so I assume you have a Request object (it should be somewhere around ;-)):
If Not Request.Cookies("parker") Is Nothing AndAlso Not Request.Cookies("parker")("id") Is Nothing Then
...
More info on reading and writing cookies in VB.Net: http://msdn.microsoft.com/en-us/library/ms178194.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-7

In asp, how to set boolean values to english?

When I run this:
<%
www = false
response.write www
response.write "UPDATE table SET domain='"&www&"' WHERE id=n"
%>
I get this:
false
UPDATE table SET domain='Falso' WHERE id=n
Notice the 'Falso' word that is in Portuguese instead of English.
Is it possible to change the boolean values to English?
I have a Windows 2008 / IIS 7 in pt-BR.
This question was asked just recently here
I don't have a good machine to test the following code, which came from a working solution. It forces the locality you need (of course you can change the locality to what you need it to be, if 1033 is not your goal)
<%
Response.Write FormatDateTime(Now) & "<br />"
oldLocale = SetLocale(1033) '1033=English(US)
Response.Write FormatDateTime(Now) & "<br />"
SetLocale oldLocale
Response.Write FormatDateTime(Now) & "<br />"
%>
I'll not be able to provide any more testing for this 'issue' anymore.
That's because I've made a decision to format my windows and install a new one now in english.. I did this because I'm running out of time, I need to put this server working as soon as possible..
But I want to thank everyone who contributed on finding the resolution for this problem =)
If anyone is having the same issue, please leave your comment, so the others can provide more options to try to solve this.
If you dont mind changing the code, you could use a function to print the boolean value. For me thats not an option, but i'm starting to believe its the only way.
Function PB(pVal)
If pVal Then
PB = "true"
Else
PB = "false"
End If
End Function
Response.Write "UPDATE table SET domain='"&PD(www)&"' WHERE id=n"
Just use string instead:
www = "false"
Then it won't be affected by regional settings.
If you want to keep working with actual boolean values, use Parameters instead of raw SQL.

How can I load a dynamically generated XML file?

Assume I have a file that contains :
<%
Response.write("<my_tag>value</my_tag>")
%>
If I get it as an ordinary XML file, I get an error telling me that the XML have not the right format because it begin by "<%". How can I read this XML dynamically generated ?
Edit:
In fact, it was an illusion. The Server.Execute method just print the other file. What can I do ? How could I put the result of an ASP page in a string that I could read by loadXML method ? Or how could I just process the file before loading it ?
Give it a file extension that ASP will know to process, or tell ASP to process the file extension you're using. The server has to know to process the file and give you the dynamic result. It doesn't treat every file served as a classic ASP file, you have to tell it what to treat the file as if you're using a non-standard extension for ASP. You can do this by mapping the classic ASP handler to the file type you're trying to HTTP GET.
Use an .asp extension and set the Content Type:
<%
Response.CharSet = "utf-8"
Response.Buffer = True
Response.ContentType="text/xml"
Response.Write "<?xml version=""1.0"" encoding=""utf-8""?>"
Response.Write "<my_tag>value</my_tag>"
Response.Flush
%>
You might take a look here: http://www.w3.org/TR/REC-xml/

Conditional includes in Classic ASP - where the file may not exist on the server

I am currently in a situation where I have to make some additions to an application written in classic ASP using server-side JScript on IIS.
The additions that I need to make involve adding a series of includes to the server-side code to extend the application's capabilities. However, the inc files may not exist on the server in all cases, so I need the application to fall back to the existing behavior (ignore the includes) if the files do not exist, rather than generating an error.
I know that this can't be accomplished using if statements in the JScript code because of the way that SSI works, and have not come across any ways of dynamically including the code on the server side, where the files may not exist.
Does anyone know of a way to accomplish this in classic ASP? Any help would be much appreciated.
Here's a script to dynamically include asp files:
<%
' **** Dynamic ASP include v.2
function fixInclude(content)
out=""
if instr(content,"#include ")>0 then
response.write "Error: include directive not permitted!"
response.end
end if
content=replace(content,"<"&"%=","<"&"%response.write ")
pos1=instr(content,"<%")
pos2=instr(content,"%"& ">")
if pos1>0 then
before= mid(content,1,pos1-1)
before=replace(before,"""","""""")
before=replace(before,vbcrlf,""""&vbcrlf&"response.write vbcrlf&""")
before=vbcrlf & "response.write """ & before & """" &vbcrlf
middle= mid(content,pos1+2,(pos2-pos1-2))
after=mid(content,pos2+2,len(content))
out=before & middle & fixInclude(after)
else
content=replace(content,"""","""""")
content=replace(content,vbcrlf,""""&vbcrlf&"response.write vbcrlf&""")
out=vbcrlf & "response.write """ & content &""""
end if
fixInclude=out
end function
Function getMappedFileAsString(byVal strFilename)
Dim fso,td
Set fso = Server.CreateObject("Scripting.FilesystemObject")
Set ts = fso.OpenTextFile(Server.MapPath(strFilename), 1)
getMappedFileAsString = ts.ReadAll
ts.close
Set ts = nothing
Set fso = Nothing
End Function
execute (fixInclude(getMappedFileAsString("included.asp")))
%>
The last line (the one starting with "execute") is equivalent to an "include" directive, with the difference that it can be included inside an "if" statement (dynamic include).
Bye
If you are really brave, you can read the contents of the file and then Eval() it.
But you will have not real indication of line numbers if anything goes wrong in the included code.
As a potentially better alternative: Can you not create some sanity check code in global.asa to create the include files as blanks if they do not exist?
Put simply, no. Why would the files not exist? Can you not at least have empty files present?
What you could do is something like this:
Use Scripting.FileSystemObject to detect the presence of the files
Use Server.Exeecute to "include" the files, or at least execute the code.
The only problem is that the files cannot share normal program scope variables.
The solution to this turned out to be to use thomask's suggestion to include the files and to set a session variable with a reference to "me" as per http://www.aspmessageboard.com/showthread.php?t=229532 to allow me to have access to the regular program scope variables.
(I've registered because of this, but can't seem to associate my registered account with my unregistered account)

Resources