views:

231

answers:

2

We are talking about Classic ASP and NOT ASP.NET!

Lets start from top. We are using ISAPI_Rewrite and we would like to dynamically offer our customers to control rewriting of urls (giving them httpd.ini is not an option). We were thinking that all unknown url requests (we define this in httpd.ini) are controlled by one asp file which creates a GET request to select url (customers creates key -> value table). Now, we can make a request to another page and just print the output but we cannot make a request to our own server. As I am aware, ASP doesnt offer this.

We could write a .NET extension to control this but we are looking for other options. I know that declining .NET is a stupid thing, but its a long story...

Is there a solution to this problem in ASP?

+2  A: 

Have a look at Server.Execute it allows dynamic (run time) code inclusion of other ASP files. An added bonus is that it's treated as part of the original request so SESSION, COOKIE are all available in the included file. HOWEVER variables defined in the master are not available to the included the page. You circumvent this using temporary Session variables though.

Session("variable") = "value";
Server.Execute(url);
Session.Abandon;
Response.end;

Session.Abandon will clear ALL session variables, you might want to clear them individually.

Martijn Laarman
I did notice this solution on few blogs and I like it. Only problem is that modifying a large number of files to support temporary session is not an option so it has to support passing the variables to included file...
FrEaKmAn
I updated with an example on how to set and clean-up the session variables, to show its not very intrusive. It would be a simple find and replace on all the inlcuded files to reference the session instead. (CODE is in JScript but still classic ASP)
Martijn Laarman
@Martijn: this assumes that there isn't an otherwise valid reason for maintining session variables in other asp pages. I use the Session variable/Server Execute approach but since Iknow which variables I've set, I simply remove them after the call to server.execute.
AnthonyWJones
True Anthony, I just posted it up as an example but probably should have mentioned it.
Martijn Laarman
I've used Server.Execute extensively and you can't rely on using Session to store temporary stuff since if the user accesses multiple pages simultaneously you can corrupt it's value. If the app is well designed to use Server.Execute there should be absolutely no need for the bits of code being executed in isolation with Server.Execute to have any knowledge of each other or pass stuff around
RobV
A: 

You can make a request to your own server but the page making the request needs to NOT have session enabled in the page declaration right at the top of the page:

<%@ EnableSessionState=False %>

Each page locks the session object and its that which stops you making a request to your own server. If you declare you are not going to use session in the calling script then it wont lock it and you can run it again using a XMLRequest and pass what you like on the querystring, post data and session cookies too so session etc. will all still exist.

Pete Duncanson