Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How To.. 2

Status
Not open for further replies.

ermora

IS-IT--Management
Apr 5, 2004
70
US
I have a website that, until now, worked fine using a single .asp page that checked a specific query string. For example:


The page would be process using <SELECT CASE> and would load the server side include (SSI) file specified by the <CASE "FlyingHigh">.

The problem is that I've introduced a new .asp page that is a form and when using the POST method and this particularly designed website, I get an error (HTTP 405 - Resource not allowed).

I hope I explained it clearly. Does anyone have a solution other than breaking away from using SSI to process the form results?

Regards,
Ed
 
Negative, the action reads ="?page=ProcessApp" with hidden input fields for record identification.

Leaving these settings alone and changing the method to "get" works, however, the resulting query string is too large (too many input fields) and is truncated - this, in addition to the visibility of the resulting url is why I want to go with "post".

Regards,
Ed
 
If you use Request.Form("variablename") instead of Request.QueryString("variablename") you'll be able to access the POST form element values.

Lee
 
I know how to access form elements, the problem, I believe, is that the forms' action does NOT specify a specific .asp page - so the server automatically loads the "default document" on the root of the website, which uses the QueryString("page") to load the appropriate SSI.

That being said, the code within the "default document" would look something like this:

<%
Dim strPage
strPage = Request.QueryString("page")
%>

<...html stuff...>

<%
SELECT CASE strPage
CASE "ContactUS"
<!--#Include File="contactus.asp"-->

CASE "ProcessContactUS"
<!--#Include File="processcontactus.asp"-->

CASE "FlyingHigh"
<!--#Include File="flyinghigh.asp"-->
<%

<....html stuff...>


Regards,
Ed
 
Thanks for the post Lee and I appreciate your input, but I'm not doing dynamic (variable based) SSI, nor is there an issue with putting the <!--#Include "outside" the <% asp code %> - even though in the above example I didn't show that (where's the edit post button!?)

Regards,
Ed
 
Alright, a little more testing and this is what I've found....

Without changing anything with the exception of the "action" from "?page=ProcessContactUS" to "/default.asp?page=ProcessContactUS", it now works.

Very strange behavior. But I'm not satisfied - I really don't want the url to specify a particular document. Is there anyway around this weird issue?

Regards,
Ed
 
This, copied from the example in your third post
Code:
<%
SELECT CASE strPage
 CASE "ContactUS"
 <!--#Include File="contactus.asp"-->

 CASE "ProcessContactUS"
 <!--#Include File="processcontactus.asp"-->

 CASE "FlyingHigh"
 <!--#Include File="flyinghigh.asp"-->
%>
is dynamic SSI. Dynamic/conditional what you described in your original post, too. Were you not aware that a Select Case is considered a conditional statement, just like If/Else?

Lee
 
Making the "page" a hidden field and setting the action="/", still results in the HTTP 405 error.

It seems using a website that uses SSI to process a form, you must specify the default document within the action (i.e. action="default.asp") to work around this HTTP 405 error.

I hope this isn't true because I don't want to display that within the URL itself. Maybe someone has a solution?

As to dynamic SSI, based on the first link you provided, their description of dynamic SSI differs from what you say.

Regards,
Ed
 
Ed,

Lee is correct when he states that you are trying to do dynamic includes.

One thing you may or may not be aware of is that ALL of those pages are loaded into the calling page BEFORE the ASP parser interprets the ASP code. This means that if you have 10 pages inside 10 select case statements, your server will be loading all 10 of them, putting the content (e.g. code) from each of them as a replacement of the <!--#include...> tag, then once it has this big long script, it executes the code.

I doubt this is what you expected... most people assume that it will only include the content of the file if the condition is met... but this is not how SSI and ASP works. SSI is called first, then ASP code is executed once all the content has been combined. (hence why it is not actually part of the ASP code, and can be used in a HTML file.)

There are ways to emulate dynamic includes, for example the Server.Transfer or Server.Execute functions or FSO and Execute()

If you already understand that, and are happy with that design then simply ignore us, Lee and I are simply pointing out a common misconception that's not usually preferred behaviour.


In regards to your stated problem, this works:

Default.asp
Code:
<%

if Request.QueryString("x") = "form" then

	%>

	<!--#include virtual="/test/form.asp" -->

	<%

else

	%>

	<!--#include virtual="/test/form2.asp" -->

	<%

end if

%>

form.asp
Code:
<html>

<head>

</head>



<body>

<form method="post" action="./?x=result">

	<input type="text" name="test" />

	<input type="Submit" value="Submit" />

</form>

</body>

</html>

form2.asp
Code:
<%

Response.Write(Request.Form("test"))

%>

Try it for yourself and see. Then look at your own code to see what is different.

Also, your example code puts the <!--#include...> inside the ASP code... this is not correct, and will not work, hence I have refactored your example to put it outside the <% %> tags.

So, what exactly is the code in these included files ? maybe that is the source of your problem - but we have no idea what that code actually looks like, so you're going to have to share if you want any more advice.



A smile is worth a thousand kind words. So smile, it's easy! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top