views:

185

answers:

3

Is it possible to return to the web client a page named differently than the original classic asp page read from the web servers folder ?

F.i. a real example I would like to implement: let's say I have an classic asp called

calendar.asp

If this page is called today (Jan 6, 2010) the page returned to the client web site should be:

calendar-of-january-6-2010.asp

If the same page should be called tomorrow, the page returend to the client web site should be:

calendar-of-january-7-2010.asp

You get the picture. Based on some internal logic, return a specific named classic asp page to the web client .

Thanks for any input you might provide.

UPDATE: The specific date files in the above example do not exist physically (or I could use a redirect). I was hoping to find something like I use to return a csv file:

Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "attachment; filename=export.csv"

Not the same, of course, cause this will let the client browswer prompt for the save/open box. Just something similar.

+2  A: 

OK, seen your edit about wanting to link to daily calendars.

Think of it like this:

  1. Build your pages so that the links are to friendly URLs - /calendars/jan-01-2010.asp, /calendars/jan-02-2010.asp, and so on.
  2. Configure IIS to use a custom 404 error for /calendars/ - so that whenever a client requests a page here that doesn't exist, your server will run calendar.asp (instead of just sending back "404 Page Not Found")
  3. That's it. Your client will never see the URL "calendar.asp", because they're never requesting it. All they're doing is following the friendly links you're giving them. It's your server that's doing the clever bit (catching the "invalid" requests, and pretending there's actually a valid page at that URL)

StackOverflow works like this - it uses ASP.NET MVC and the ASP.NET routing engine to intercept those friendly-looking question URLs, look them up in the database, and return a generated page, so that to users (and search engines) it looks like there are thousands of friendly-named pages, when it's actually all happening behind-the-scenes.

Dylan Beattie
But even than, the returned name to the client is not the one with the date in, no ?
Edelcom
@edelcom: No name is ever returned to the client. The client specifies the resource required, the server sends the resource, it doesn't see any need to supply a name for it since the client already knows it. The only way you can get the server to change the name of the item being requested is using a Response.Redirect which in effect is telling the client "please request this resource instead". Your goals of doing this and being friendly to search engines seem to be in conflict with each other.
AnthonyWJones
Thx Dylan, this helpt me a lot. I never realised that a name is not returned to the client. Learned something today , yes !
Edelcom
@Dylan Beattie: I tried to implement this, but there is still one thing I don't understand: if I configure IIS to return a page called calendars.asp (rerouted from /calenders/jan-01-2010.asp), the page name the user sees in his browser is calendars.asp NOT /calenders/jan-01.2010.asp (or I configured IIS wrong of course).In SO the name at the top is the same name as the link you clicked, so although it was rerouted, somehow the actual page returned is once again the name of the clicked link NOT the page which has provided the dynamic contents. I am puzzled here ...
Edelcom
@Edelcom - sounds like you've configured IIS wrong. You need to go into the Error Pages feature, and for status code 404, instruct the server to "Execute a URL on this site" - and specify /calendars/calendar.asp as the URL to execute.If you're setting up any kind of redirect (whether via IIS Custom Errors, or using Response.Redirect in your code) then you've got it wrong - a redirect won't give you the results you're after.
Dylan Beattie
@Dylan Beattie: I did just that. Redirected to calendar.asp, but that way the calendar.asp is returended as page and visible i the browsers address bar. It would be nice if the user still should see /calenader/jan-01-2010.asp, althought it's contents should be generated by calendar.asp.
Edelcom
@Dylan Beattie: aha wait, maybe I do a redirect too many in the page called from IIS. Will try that and let you know the results. Thanks ...
Edelcom
You should not be doing ANY redirects - anywhere. No redirects. None in your pages, none in the IIS configuration, nothing. The ONLY thing you need to configure is the IIS custom handler for 404 errors. The second you send a redirect header, you've sent the browser off to a different page, which WILL appear in the browsers' address bar...
Dylan Beattie
A: 

You could write a custom ISAPI filter (C++), to control which physical file gets mapped to the URL. You need admin access to the IIS box(es) to install this filter, and if you really want your custom URLs to feature the .asp extension, your filter needs to accomodate this (since ISAPI filters are primarily selected based on extension by IIS). Check this and this MSDN link. This codeproject sample contains some more pointers (it remaps .chm to .asp files, easy to follow).

tijmenvdk
I know I could write an ISAPI filter (not that I have done that before, though). The question is just if there some way (by fiddling the headers somehow) that using classic asp, this can be achieved.
Edelcom
As far as I know this is the only way to achieve this in ASP, since the standard asp.dll simply looks for the file based on the URL and report an invalid page request without touching the global.asa.
tijmenvdk
@tijmenvdk, I think IIS can be configured to send asp all requests, even bad ones. The process is similar to sending it new extensions. But its been years since I did this for a cms
ccook
A: 
  1. You can just redirect to the new page from calendar.asp. When user requests this new page use URL rewriting to rewrite back to calendar.asp internally.

  2. Not so good - on first request to calendar.asp generate the actual page (the one with the date) (don't forget to delete it in 24 hours) and redirect to this page.

DmitryK