Setting connection with function - asp-classic

I am trying to use ASP to create a connection to my database and i have the following connection code:
Set objConn = ConnectDB()
Set objRS = objConn.Execute(query)
I have an include file that I have at the top of my page:
<!--#include FILE=dbcano.inc-->
And I get this error when I call my page:
Microsoft VBScript runtime error
'800a01f4' Variable is undefined:
'ConnectDB' patti_trinkets.asp, line 9
The ConnectDB() is a function I created that is stored within the dbcano.inc file.
Any suggestions as to why I am getting this error when I call my page?
My full code can be found here: http://pastie.org/337183

Shouldn't you try
ConnectDB(objConn)
instead?

Well. It finds the include file because you dont get the
"Active Server Pages error 'ASP 0126'
Include file not found The include
file 'dbcano.inc' was not found
But your function ConnectDB that I presume should return a connection object is not recognized as a function, therefore it thinks it is a undefined variable.
To know why, we really need to se the code in the include file too.
And by the way, make sure to stop your server to serve the content in the .inc -file. Too many times, you see sites where the inc-file has been moved, and some old page serves up the "Include file not found. The include file "dbhandler.inc" was not found" and then you only have to enter dbhandler.inc in the browser to get the sql-server name/ip, connectionstring and everything. This is well known but still a common thing, just google the error message with a couple of more keywords to get a list of exploitable sites.

Related

Not able to download file name containing 'aspx' character in asp .net

Am developing asp .Net web application.
In one of my aspx file am using file to download using generic handler. Everything works great. But when am testing i felt a strange problem. That, if am uploading a image or document with file name containing aspx character for Eg; aspxphoto as file name.
Uploading doesnt have any any problem but when i try to download it is throwing error in Generic handler file as
Object reference not set to an instance of an object.
Can anyone help me why this problem happends and how can i fix it?
You will not be able to do this. The IIS handler wants to "handle" the ASPX. You should simply not allow it, or if you have to, rename it to .aspx.uploaded or something. If you allowed, it you could open yourself to hacking.
As another option, you may be able to create a virtual that implements ("no processing") - possibly using the HTTP Handler under the virtual and just disabling script / execute permissions (under handler >> Edit Feature Permission >> Script OR under Virtual >> Edit permissions >> Special >> Turn Execute off.
I would not recommend the last, since it will add complexity when migrating between test and live AND for recovery (DR).

GET and .xq files

When using exist-db, a GET message will obtain an entire file from a collection (by providing the URI). In the case of a .xq file, however, the same GET message will instead execute the file.
I am wondering if there is anything I can attach to a GET message to cause exist-db to return the file rather than execute it. I should have all the necessary permissions, or I should be able to set them.
Thank you.
Assuming you are running eXist as a stand-alone server:
"GET accepts the following request parameters, which must be URL-encoded" _source=yes | no - which "Specifies whether the query should display its source code instead of being executed" - see the developers guide online for full details & example usage.
eXist sets this capability to 'no' as default in it's config - however you can override this permanently by adding specific files to the <allow-source></allow-source> section in the Web-application Descriptor file (descriptor.xml) read from WEB-INF directory of the web application or from the directory specified by the exist.home system property.
Hope that helps.

Parameter is not valid error when creating new bitmap

I am displaying images on my page and then attempting to find the current height of the images in order to vertically position them. I am doing this by creating a new bitmap and then getting the height of the bitmap, as follows:
Dim sampleImg As New System.Drawing.Bitmap(Server.MapPath(String.Format("/Uploads/Products/Images/w100h100/{0}", e.Item.DataItem("Filename"))))
Dim imgHeight As Integer = sampleImg.Height
When I run this on my local machine, all works fine. However, I have recently uploaded the site so far to my development server and when I run the same code from there, I get this error message:
Parameter is not valid
I have been searching forums to try to find a solution but I have ended up a bit unsure where else to look because the file definitely exists on the development server and the code works fine on my local machine. The server I am using is a VPS and I am quite a beginner with working with servers so I don't know if there is anything I haven't set up on there which is stopping it from working?
Whilst trying to find a solution, I have also tried the following code but I get a System.IO.FileNotFoundException error message:
Dim sampleImg As System.Drawing.Image = System.Drawing.Image.FromFile(Server.MapPath(String.Format("/Uploads/Products/Images/w100h100/{0}", e.Item.DataItem("Filename"))))
I am wondering if anyone can help me find a solution to this, or alternatively is there a different method to acheiving the same end?
All help is very much appreciated. Thanks.
It may be a file permissions issue, you need to ensure that the IUSR account for your site has read access to the image file. To do this -
R-click the file, Properties, Select the "Security" tab - you will have a list of users who have access to the file. A quick check is to add "Everyone" with read priviliges. To keep it locked to your ASP.Net instance only you should start IIS Manager, r-click your app pool and the Identity is the user your app runs under.
If you are running through IIS it may be that the file type isn't set up in the available MIME types for the site.
http://technet.microsoft.com/en-us/library/bb742440.aspx
With IIS7 there is a module for each Site called "MIME Types". Check whether the File Extension is in the list, and if not, add it with the appropriate MIME Type (list of mime types in link above)
I think you have to use ~ root operator to resolve the path issue.
Dim sampleImg As System.Drawing.Image =
System.Drawing.Image.FromFile(Server.MapPath(
String.Format("~/Uploads/Products/Images/w100h100/{0}",
e.Item.DataItem("Filename"))))
OR the specified file is not a valid image file.

Why does ASP.NET publish my local folder paths?

In a common ASP.NET Web Forms page, I specify the location of a backup file as follows:
string backupFilePath = "../data/backups";
ICronjobTask[] tasks = new ICronjobTask[]
{
new FileBackupCronjobTask(backupFilePath)
};
The ICronjobTask is executed later on. When calling the published page on my web server, an error message tells me that parts of the path "C:\Windows\SysWOW64\inetsrv\data\backups\file.txt could not be found.
Why does ASP.NET publish my local directory structure? How do I turn this off?
You're displaying the raw exception error message, is my guess. Whenever you do that, you risk giving away information that you don't want to be made public. Instead of doing that, you should interpret the exception and give general information to the user.
The solution was to use the Server.MapPath(string path) method that returns the physical path corresponding to the specified logical one.

File.OpenText method is not declared error

I have a FileUpload control from which I need the path of a text file. After selecting the file, I need to open and read the data from the text file. For this, I used the following code to open the text file.
fp = File.OpenText(FileUpload2.PostedFile.FileName);
This is working fine on my system. The FileUpload2.PostedFile.FileName property gives the full path of the file. The File.OpenText(() method opens the selected file. But when I run my project in IIS, it gives the following error:
"File.OpenText is not declared."
The FileUpload2.PostedFile.FileName property is not retrieving the full path. It retrieves only the file name. What could be the reason?
This is a typical client server issue. On your system it works, because you are the client and the server, but on IIS (I assume you mean IIS on a test/production server) it looks for the file on the IIS server system while you select the file on your system.
You should use the FileUpload2.PostedFile.InputStream property instead of the filename property.
File f = new File("x.txt");
if(f.exists())
{
.....
}

Resources