asp #include, and error console for asp? - asp-classic

I'm trying to understand ASP but #include doesn't seem to work for some reason. I'm using IIS 7.5 (included with Win 7).
I have two .asp files in .../wwwroot/MyWeb/. I'm trying to #include FiboRecursive.asp in a file called test.asp. Both files work separately if I remove the #include. I have tried both virtual and file includes.
This is test.asp:
<%# language="javascript" %>
<html>
<body>
<p>
<% //Response.Write(Request.ServerVariables("http_user_agent"));%>
</p>
<p>
<%
var remoteAddr = Request.ServerVariables("REMOTE_ADDR");
remoteAddr += "";
if ((remoteAddr.length > 5) && (remoteAddr.substr(0,7)=="140.114") ) {
Response.Write("Hello there Tsingda student!");
}
else {
Response.Write("You're not a Tsingda student!");
}
%>
</p>
<form action="./FiboRecursive.asp" method="post">
<input type="submit" value="Calculate Fibonacci numbers!" />
</form>
<!--#INCLUDE FILE="fiborecursive.asp" -->
</body>
</html>
This is the code in FiboRecursive.asp:
<%# language="javascript" %>
<%
Response.Write("Let's calculate some Fibonacci numbers!");
%>
Edit: Another thing: I always use web developer tools (error console) in Firefox to check for errors in my code, but obviously that doesn't work too well when doing server side stuff. Any way to get some hints as to what's wrong from a console or similar?

You should not have the # command within your include file as this will (in ISS version 5.1 at least) result in the following error:
Error Type:
Active Server Pages, ASP 0141 (0x80004005)
The # command can only be used once within the Active Server Page.

Related

asp.net/vb webpage not redirecting

I've got some legacy websites that have been migrated to Windows Server 2019 and have found out that the code no longer seems to be functioning correctly. This is code for a simple poll/voting system. The problem that I'm currently running into is that when any of the links are clicked, it technically doesn't redirect from the page it's on. for example the PollList.aspx page (www.mysite/admin/PollList.aspx) has a few links on it. one of them is to load up the page PollEdit.aspx so a new poll can be added. the URL it's supposed to redirect to is www.mysite/admin/PollEdit.aspx?ID=0 (new poll only created by admins). however what it redirects to is: www.mysite/admin/PollList.aspx/PollEdit.aspx?ID=0 and stays on the current page.
Can someone show me what's broken? This was migrated from a Windows Server 2008r2 to Windows Server 2019. Let me know if there's any info needed.
below is the related content from the PollList.aspx page. everything else seems to be working just fine:
<form id="Form1" method="post" runat="server">
Edit Voter Permissions
<h1><center>Polls</center></h1>
<asp:repeater id="lstPolls" runat="server">
<HeaderTemplate>
<%= "<table border=0 cellpadding=0 cellspacing=4 align=center width=80% >" %>
<%= "<tr><td></td><td align=center><font size=2><a href=PollEdit.aspx?ID=0>[new poll]</a></font></td></tr>" %>
</HeaderTemplate>
<ItemTemplate>
<%="<tr bgcolor=#B3C9EF>"%>
<%# PrintPollItem(Container.DataItem)%>
<%= "</tr>" %>
</ItemTemplate>
<AlternatingItemTemplate>
<%= "<tr bgcolor=""#DFEBFF"">" %>
<%# PrintPollItem(Container.DataItem)%>
<%= "</tr>" %>
</AlternatingItemTemplate>
<FooterTemplate><%= "</table>" %></FooterTemplate>
</asp:repeater>
</form>
and below is the code behind content for the PrintPollItem() func:
Protected Function PrintPollItem(ByVal myPoll As BLL.Poll) As String
Dim txtTemp As New System.Text.StringBuilder
txtTemp.Append("<td>")
txtTemp.Append("<a href=PollEdit.aspx?ID=" & myPoll.ID.ToString() & ">")
txtTemp.Append(myPoll.Name)
txtTemp.Append("</a>")
txtTemp.Append("</td>")
txtTemp.Append("<td width=200 align=center>")
Select Case myPoll.OpenStatus
Case -1
txtTemp.Append("poll closed: <font size=2>[view results]</font>")
Case 1
txtTemp.Append("poll open: <font size=2>[view results]</font>")
Case Else
txtTemp.Append("poll pending: <a href=PollList.aspx?ID=" & myPoll.ID.ToString() & "&Action=open><font size=2>[open now]</font></a>")
End Select
txtTemp.Append("</td>")
Return txtTemp.ToString()
End Function
href you can give full path or relative path
you can use / or ../ or ~/ Before Assigning Link, That indicates current Files or Folder
Try href=/PollEdit.aspx

Using Request.QueryString in ASP.NET Embedded Code Block

I am attempting to pass a parameter from one file to another via the URL after a button is clicked. These are written with Express.js (index.ejs to items.ejs).
As it stands currently I am setting the URL parameter in a defined Javascript function:
function loadItems(page, subcategory) {
window.history.pushState(null, null, "?subcat=" + subcategory) //param set
$('#mainContent').load(page);
}
where subcategory is the changing variable.
From there I am trying to read this parameter during an ASP.NET function written in embedded code blocks.
<% if(items[i].subcategory === Request.QueryString["subcat"].Value) { %> //get param
<% if (items[i].status === "Supported") { %>
<tr class="success">
<td>Edit</td>
<td id="item name"><%= items[i].name%></td>
<td id="subcat name"><%= items[i].subcategory%></td>
<td id="item status"><%= items[i].status%></td>
<td id="item desc"><%= items[i].description%></td>
</tr>
However I am met with an error which states Request is not defined and a callback to the above if statement. It is my understanding that on the ASP.NET side of things, Request.QueryString is a part of System.Web.HttpContext.Current.
How would I go about including this into my code blocks so that I am able to pull the parameter from the URL? Or, if this is not the way to be looking at this problem, how should I go about it?
My advice would be to use code behind. Embedded code blocks are an old-school throwback from the asp days. But if you must, then you should be able to do something like this:
<%# Page Language="VB" %>
<script run=server>
Protected Function GetSubcat() As String
Return Request.QueryString["subcat"].Value
End Function
</script>
<form id="form1" runat="server">
Subcat value is <% =GetSubcat()%>.
</form>

Can I write JSP script in wordpress

I am making a JSP program and all it does is show the date:
<html>
<body>
<%
System.out.println( "Evaluating date now" );
java.util.Date date = new java.util.Date();
%>
<p>Hello, the date is
<%
out.println( date );
out.println( "<BR>Your machine's address is " );
out.println(request.getRemoteHost());
%>
</p>
</body>
</html>
On wordpress, all the JSP script shows up as normal text and I don't know why.
Short answer is no. JSP files must be run on an application server such as tomcat. The information here might be helpful.

change frames/iframes to just one page #aspclassic

How do I rewrite the following PHP code in Classic ASP?
<head></head>
<body>
<h1>Test</h1>
<section><?php echo include('content/'.$_GET['p'].'.php') ?></section></body>
If the url is http://foo.bar.com/admin.php?p=pages, then content/pages.php is shown.
You can't do this with INCLUDE but you could use Server.Transfer instead, eg.
Server.Transfer "content/" & Request.Form("p") & ".asp"
Never trust what comes from the clientside (browser) as they can try to hack you.
Since it is not likely that "shdyhio3hlkehio.asp" or similar is a proper file, you should limit the options to your actual selection and also have a default file which is a "catch all other requests".
Combine that with Server Side Includes and you have your setup ready.
You should also check if the user actually requested a page -- if "p" is empty then show a default message.
Note the use of LCase in the "Select Case"-line and lowercase values in the Case-lines.
This is due to the face that the string comparison is case-sensitive, meaning "about" (lowercase "a") and "About" (uppercase "A") is not the same.
Eksemple:
<% If Request.QueryString("p") = "" Then %>
no specific page was request, show a default message
<% Else %>
<% Select Case LCase(Request.QueryString("p")) %>
<% Case "content" %><!-- #include file="content.asp" -->
<% Case "about" %><!-- #include file="about.asp" -->
<% Case "contact" %><!-- #include file="contact.asp" -->
<% Case Else %><!-- #include file="404.asp" -->
<% End Select %>
<% End If %>
You can use something like this
<!--#include file="somefile.asp"-->
in your HTML file .

ASP Classic - Include VBScript page in a JavaScript page?

Is there a way to include a VBScript page into an ASP page written using Javascript?
There is an ASP page written in Javascript, but our sidebar menu is written in VBScript. When I include the sidebar asp file into the Javascript the server gives an error.
< %# LANGUAGE="JavaScript" %>
<%
...
< !--#include file="sidebar.asp"-->
...
where sidebar.asp is written using VBScript.
You can try this, but my guess is that the sidebar.asp will be executed before your Javascript code.
< %# LANGUAGE="JavaScript" %>
<%
...
<script language="VBscript" runat=server>
< !--#include file="sidebar.asp"-->
</script>
...
I do this all the time, but I write my ASP/JScript pages a bit differently. Instead of switching the page language to "JavaScript", I leave it at the default "VBScript" and then use a <SCRIPT LANGUAGE="JavaScript" RUNAT="Server"> block for my JScript code. The JavaScript SCRIPT blocks are executed before the normal <% %> tags, so I do all my page processing in the SCRIPT blocks and then simply plug the results into the page with <% %> tags. Here's an example:
mainpage.asp:
<SCRIPT LANGUAGE="JavaScript" RUNAT="Server">
var name;
var address;
var phone;
function main() {
var rec = go_to_database();
name = rec.first_name + " " + rec.last_name;
address = rec.address;
phone = rec.phone;
}
</SCRIPT><% main() %>
<html><head><title><%= name %></title></head><body>
<p>Name: <%= name %><br/>
Address: <%= address %><br/>
Phone Number: <%= phone %></p>
<!--#include file="subpage.asp"-->
</body></html>
subpage.asp:
<p>Blah blah blah, some random VBScript code: <%
Dim whatever
whatever = some_silly_thing()
Response.Write(whatever)
%>.</p>
So, first IIS processes the SSI and includes subpage.asp into mainpage.asp. Then, it evaluates the JScript SCRIPT block, declaring the variables name, address, and phone and defining the function main.
Then it evaluates each <% %> tag in order. <% main() %> call the main function and sets values for name, address, and phone. Then <%= name %>, <%= address %>, and <%= phone %> substitute those values into the page. Finally, the <% %> code from subpage.asp is evaluated and the Response.Write value ends up in the page output.
While the whole page is not written in JScript, the vast majority of the code can be, inside the SCRIPT block. Would that work for you?

Resources