Classic ASP - Request object Is Empty - iis

I'm working on adding a feature to an old classic asp site and ran into an interesting problem. The following line on the page results in the helpful error "Object required:'' "
strServerName = Request.ServerVariables("server_name")
When I attached a debugger to look at it, Request is in fact Empty, which I don't understand how that can happen? This line exists on several pages and executes with no problems besides this one. In this case, the page is executed by a Redirect from another page.
I've been searching for a solution for a day or so now and haven't been able to locate anything that's been helpful. I'm desperate, any ideas would be greatly appreciated.
Oh, and if any more information is required, please don't hesitate to call me out.
Thanks!
Update 1
As requested, below is the entire code snippet wrapped in <% %> tags. This block exists as first code within the file (named 'order-results-instant.asp'):
<%
strServerName = Request.ServerVariables("server_name")
strServerName = UCase(strServerName)
strServerURL = "http://localhost/cbr"
strServerURLhttps = "https://localhost/cbr"
strConnect = "Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=CBR; Integrated Security=SSPI"
Dim objConn
Dim sql_stmt
Dim rs
%>
Update 2
I've used the following 2 methods to redirect execution to this page - perhaps this can cause the request to be lost?
'Response.Redirect strServerURL & "/order-results-instant.asp?gwstep=1"
Response.Write "<META HTTP-EQUIV=""refresh"" content=""5;URL=" & strServerURL & "/order-results-instant.asp?gwstep=1"">"

Scan through the rest of the code. At the Global level you will find this:-
Dim Request
Rename this variable and its current usage and the Request object attached to the script context will become visible.

On your server is the Active Server Pages Web Service extension allowed (turned on) ?

I copied your code into my test asp file with the following code and it redirected just fine.
<%
strServerName = Request.ServerVariables("server_name")
strServerName = UCase(strServerName)
strServerURL = "http://localhost/"
strServerURLhttps = "https://localhost/"
strConnect = "Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=CBR; Integrated Security=SSPI"
Dim objConn
Dim sql_stmt
Dim rs
Response.Write(strServerName)
if Request.Querystring("test") <> "1" then
Response.Redirect("http://" + strServerName + "/asptest.asp?test=1")
end if
%>
The only real difference is I am adding "http://" to the redirect. Maybe something I did will shed some light to help you solve your issue.
thanks

Does it work if you try to access it at an earlier point in the page?

Related

write in event log in vb.net

I've developped a sharepoint 2007 feature in vb.net.
Inside, have an application page and in onload method, i want to write message in event log
Dim cs As String = "TESTLOG"
Dim elog As New EventLog()
Dim sourceExist As Boolean
Try
sourceExist = EventLog.SourceExists(cs)
Catch ex As Exception
sourceExist = False
End Try
If Not sourceExist Then
Dim ev As New EventLogPermission(EventLogPermissionAccess.Administer, ".")
ev.PermitOnly()
EventLog.CreateEventSource(cs, "TESTLOG")
End If
elog.Source = cs
elog.EnableRaisingEvents = True
EventLog.WriteEntry(cs, message, EventLogEntryType.[Error])
The source is correctly created but when i try to write, i've an access denied.
I go to registry to set permission full control at everyone but still have the message.
HKEY_LOCAL_MACHINE
SYSTEM
CurrentControlSet
Services
Eventlog
Application
How can i write message in event log?
Thanks
I think you need to make sure the user account that is running the website has full access to the event log. See if the following link is of any help.
KB2028427

ActiveX dll not working on IIS 8.5

ActiveX dll not working on IIS 8.5
We have a classic ASP application that uses and ActiveX dll to generate an image on the fly. It was working find on Window 2003 with IIS6. But we're migrating it to Windows 2012 and IIS 8.5. The DLL is registered on the server, configured to run under it's own app pool (No Managed Code, Classic pipeline mode). It's virtual directory is configured to run as an application and has a handler mapping for *.dll to point to the DLL for all verbs with Execute Access rights, which is the same config for IIS6.
The ASP code to render the HTML calling DLL looks like this:
<%dim SpokeData
dim JobName
dim NumOfExperts
dim ThisDirNo
dim ThisSel
dim PAPIType
dim JobType
dim SpokeDataShort
SpokeData = trim(Request.QueryString("Data"))
JobName = trim(Request.QueryString("JobName"))
NumOfExperts = trim(Request.QueryString("Exp"))
PAPIType = trim(Request.QueryString("PAPIType"))
JobType = trim(Request.QueryString("JobType"))
CalcDate = trim(Request.QueryString("Date"))
For ScaleNo = 1 to 20
ThisSel = Mid(SpokeData,(ScaleNo*2),1)
ThisDirNo = Mid(SpokeData,(ScaleNo*2)-1,1)
If ThisSel = "1" then SpokeDataShort = SpokeDataShort & ThisDirNo else SpokeDataShort = SpokeDataShort & "0"
Next
Response.Write("<div id='Wheel'><img style='margin-left:20px' src='http://www.example.com/jpwheel/jpwheel.dll?Handler=Render&nori=" & PAPIType & "&dir=" & SpokeDataShort & "&" & Now & "'></div>")
%>
The HTML then lookslike this: <img src="http://www.example.com/jpwheel/jpwheel.dll?Handler=Render&nori=N&dir=55555050555000000000&11/05/2015 16:05:24" style="margin-left:20px"> if I try to download this directly I get a 500 error (no error log unfortunately).
It is working on IIS6, not working on IIS8.5. Can anyone cast some light on migrating ActiveX server-side DLLs to IIS8.5? One thing I haven't done is check the dependencies for the DLL, can anybody recommend a tool for that? I'm guessing with windows 2003 coming to end of life a number of people are running into issues like this.
The problem was caused by using the incorrect handler mapping. I had it setup as a Script Map. It needed to be a Module Mapping with the following details:
Request path: *.dll
Executable: Path to the jpwheel.dll
Module: IsapiModule
Name: jpwheel
Request Restrictions: All Verbs, Access required: Script
Feature Permissions: Read, Script, Execute
So it's working now.

Is it possible to embed the username/password into and ASP file to access files when anonymous access is disabled?

I'm redesigned a login system where I work and currently if someone know the path to a file they may be able to access it even if they are not logged in at all. So far I've researched and come up with 2 ways to prevent this.
Disable anonymous access and have the file brought in by the webpage. This is what I would prefer to do for now since it wouldn't require moving the files around and it seems to be relatively easy to implement. The problem with this is that if I disable anonymous access the file trying to access the document they requires the username/password. Is it possible to have to username/password as part of the ASP file to eliminate this?
The other option is to move the files outside of the website and elsewhere on the server and have the webpage bring in the file similar the first option. I want to eventually get to this method, currently it would take much more time to do this though since we would have to move the files for all of our users as well as change the programs that generate the different reports to output to their new locations.
You could do this with a rewrite rule in IIS.
http://www.iis.net/downloads/microsoft/url-rewrite
You can also do this with a Request Filtering rule in IIS.
http://www.iis.net/configreference/system.webserver/security/requestfiltering/filteringrules/filteringrule/appliesto
"Is it possible to have to username/password as part of the ASP file to eliminate this?"
Yes, if you only want to restrict access to .asp files Session variables tend to be overused in Classic ASP but this is one situation where it is completely appropriate to use one. At the start of all your restricted pages you could have something like
<% If Session("loggedin") <> 1 then Response.Redirect("login.asp") End If %>
Then you need to find a classic asp login script which sets a session variable. Google or Bing should come up with plenty, but here are a couple of links for you
https://web.archive.org/web/20211020121723/https://www.4guysfromrolla.com/webtech/050499-1.shtml
https://web.archive.org/web/20210323190338/http://www.4guysfromrolla.com/webtech/021600-1.shtml
Edit - http server request code. I haven't tested this
Set xml = Server.CreateObject("Msxml2.ServerXMLHTTP.6.0")
xml.open "GET","http://fullurlto/yourpdffile.pdf", false, "yourusername", "yourpassword"
xml.send
Response.ContentType = "application/pdf"
Response.write xml.responseText
I found a basis for the code elsewhere on this site but it didn't quite work the way I needed it to.
How To Raise a "File Download" in ASP and prevent hotlink
Dim curUser, curDir, curtype
curUser = Request.QueryString("user")
curDir = Request.QueryString("dir")
curType = Request.QueryString("type")
If curUser = Session("homefolder") Then
Set adoStream = CreateObject("ADODB.Stream")
adoStream.Type = 1
adoStream.Open()
adoStream.LoadFromFile "C:/path/to/" & curUser & curDir
Response.Buffer = true
Response.CharSet = "UTF-8"
Response.Clear
If curType = ".TXT" Then
Response.ContentType = "text/plain"
Else
Response.ContentType = "application/pdf"
End If
Response.flush
Do While Not adoStream.eos
Response.BinaryWrite adoStream.Read(1024 * 8)
Response.flush
Loop
Response.End()
adoStream.close
Set adoStream=nothing
Else
Response.Redirect "denied.asp"
End If
The file is brought in and displayed within the browser. If the user tries to see another user's files they are simply redirected. I'm currently only dealing with PDF and TXT file but it will be easy to add new files types if needed.

Assigning an existing process to an object variable?

I need to assign another application as an object and control it.
Typically, I would open a new instance of the application using CreateObject(), but in this instance I need an existing instance of the object that was already opened in Windows Explorer. The object is an Internet Explorer session that, for various reasons, I can't simply navigate to using web browser controls in Office.
Is there a way to grab this application session by its window handle or something so that I can control it using the APIs that VBA offer? It's also essential that the application stays on the page that it was on and that its entire DOM structure remains intact.
Try this in a sub, it works for me
Set objShell = CreateObject("Shell.Application")
IE_count = objShell.Windows.Count
For x = 0 To (IE_count - 1)
On Error Resume Next ' sometimes more web pages are counted than are open
my_url = objShell.Windows(x).Document.Location
my_title = objShell.Windows(x).Document.Title
If my_title Like "The Title You're Looking For" & "*" Then
Set ie = objShell.Windows(x)
Exit For
Else
End If
Next
Now do stuff with this instance of ie

Classic ASP/IIS6: How to search the server’s mime map?

This is the same question as this but I'm looking for a classic ASP solution.
I have a third party control to provide secure downloads but it expects you to provide the response.contenttype value. I'm trying to have the browser prompt with the following:
Response.AddHeader "Content-Disposition", "attachment;filename=""" & strFileName & """"
However Safari doesn't like any of the suggested content types (does odd things with the file name - like add ".exe" to the end).
application/x-msdownload
application/force-download
So I'd either like to query IIS for the correct content type or find a generic content type that would let the browser figure it out in a somewhat reliable fashion.
Typically the mimemap being used by the site is stored at server level and you can get into permission issues trying to read it. It requires some nasty ADSI code.
Have you tried the standard application/octet-stream as a mime type?
From Reading the server mimemap:
Public Function GetMimeType(ByVal Extension)
Dim oMimeMap
Dim vntMimeType
Dim avntMap()
Set oMimeMap = GetObject("IIS://LocalHost/MimeMap")
If Left(Extension, 1) <> "." Then Extension = "." & Extension
avntMap() = oMimeMap.MimeMap
For Each vntMimeType In avntMap
If vntMimeType.Extension = Extension Then
GetMimeType = vntMimeType.MimeType
Exit For
End If
Next
If GetMimeType = "" Then GetMimeType = "application/octet-stream"
End Function
Note: the code calling GetObject is required to be an Operator in WWW Service Master properties.

Resources