View Full Version : Illegal characters in include
BoldUlysses
07-22-2008, 11:38 PM
Is there any way to insert asp code into an include? I'd like to be able to do this:
<!--#include file="test_<% WriteCategoryName() %>.asp"-->
But I get:
Parser Error Message: Illegal characters in path.
I'm working on a third-party shopping cart application written in ASP, and I don't have access to the WriteCategoryName function, and as far as I can tell I can't store the output in a variable. I have very little ASP experience. Any ideas? Thanks!
PremiumBlend
07-23-2008, 06:07 AM
I believe the problem is that the <% %> tags run after includes, so it can't pass that data into the include tag properly.
What about something like this:
Dim strPageURL
strPageURL = WriteCategoryName() & ".asp"
Server.Execute strPageURL
From the method name, it looks like WriteCategoryName() will output the value to the response. This wouldn't work as is, but if you can use the data and append the category name to the extension and call Server.Execute, I think you should be good. (haven't tested)
I don't have access to the WriteCategoryName function
... just noticed this, sorry...
If inside this function is a Response.Write and the CategoryName variable isn't accessible... you're probably going to have to get creative and think outside the box.
mjlorbet
07-23-2008, 08:40 AM
1) <%= WriteCategoryName() %> would be the correct syntax, otherwise you're injecting a block of code for execution in the middle of the include statement instead of interjecting a value
2) I'm not 100% on the meaning of the <!--#include ... --> directive, but i'm pretty certain it's pre-processor, in that the <% and <%= blocks are intended for usage in display logic, and not in pre-processor directives
BoldUlysses
07-23-2008, 03:55 PM
Thanks for the replies. Some progress has been made. I found WriteCategoryName:
Public Sub WriteCategoryName()
Dim myStorage As CSearchStorage
Dim myCategoryID As Long = 0
Dim myPageTitle As String
If Not Session("Search") Is Nothing Then
myStorage = CType(Session("Search"), CSearchStorage)
myCategoryID = myStorage.CategoryID
End If
If Not Request.QueryString("CategoryID") Is Nothing AndAlso Request.QueryString("CategoryID") <> "" Then
myCategoryID = CType(Request.QueryString("CategoryID"), Long)
End If
If myCategoryID > 0 Then
myPageTitle = New CCategories().GetCategory(myCategoryID).Name
Else
myPageTitle = m_objMessages.GetXMLMessage("SearchResult.aspx", "PageTitle", "Title")
End If
Response.Write(myPageTitle)
End Sub
It was in a file called in the header section of the file in question:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="SearchResult.aspx.vb" Inherits="StoreFront.StoreFront.SearchResult"%>
Question is, how can I modify WriteCategoryName to return a usable value to the file so I can use it in an include?
PremiumBlend
07-23-2008, 04:16 PM
Question is, how can I modify WriteCategoryName to return a usable value to the file so I can use it in an include?
I would rewrite it actually. Since this is not your code, you might not know where this is being used; therefore, you could break something else.
Instead of Sub WriteCategoryName(), you could produce your own Function GetCategoryName() As String
Remove the Response.Write(myPageTitle) and put in Return myPageTitle. From here, Server.Execute should work with your page.
BoldUlysses
07-23-2008, 04:29 PM
Thanks. That actually did occur to me, but I didn't know the proper syntax. I wrote a new function immediately after WriteCategoryName():
Public Function AcquireCategoryName() As String
Dim myStorage As CSearchStorage
Dim myCategoryID As Long = 0
Dim myPageTitle As String
If Not Session("Search") Is Nothing Then
myStorage = CType(Session("Search"), CSearchStorage)
myCategoryID = myStorage.CategoryID
End If
If Not Request.QueryString("CategoryID") Is Nothing AndAlso Request.QueryString("CategoryID") <> "" Then
myCategoryID = CType(Request.QueryString("CategoryID"), Long)
End If
If myCategoryID > 0 Then
myPageTitle = New CCategories().GetCategory(myCategoryID).Name
Else
myPageTitle = m_objMessages.GetXMLMessage("SearchResult.aspx", "PageTitle", "Title")
End If
Return myPageTitle
End Function
and put this in my category page file:
<%
Dim strPageURL
strPageURL = AcquireCategoryName() & ".asp"
Server.Execute strPageURL
%>
and now it gives me this:
Compiler Error Message: BC30451: Name 'AcquireCategoryName' is not declared.
How can it decide to see WriteCategoryName() and not AcquireCategoryName() when they're right after one another and use identical code except for the last line (also WriteCategoryName() is a Sub and AcquireCategoryName() is a Function)?
Weird.
PremiumBlend
07-23-2008, 04:45 PM
You'll probably need to compile your code. You're using VB.Net correct?
BoldUlysses
07-23-2008, 04:48 PM
I believe so. Again, I have very little ASP experience, only XHTML, CSS and some PHP scripting. How do I compile the code?
Edit: Nevermind. There's a "CompileSite.aspx" file in the root directory. Will try that.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.