Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

ASP.NET Forum


You are currently viewing our ASP.NET Forum as a guest. Please register to participate.
Login



Reply
Creating virtual subdirectory
Old 06-28-2006, 10:37 AM Creating virtual subdirectory
funkdaddu's Avatar
Web Design Snob

Posts: 635
Trades: 0
I would search for this, but really wasn't sure what terms to use. I want to beable to create a script that takes a directory name and uses it like a querystring. For example I want users to type in www.mysite.com/stores/123456 where it would pull up info from a database using 123456 as the querystring. Basically instead of setting up hundreds of subdirectories that point to script.asp?id=123456 I want to automate it. Any ideas? Can I use web.config?
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
 
Register now for full access!
Old 06-28-2006, 11:19 AM Re: Creating virtual subdirectory
Ultra Talker

Posts: 251
Location: Belgium, Antwerp, Zoersel
Trades: 0
You can use .htaccess:

Code:
RewriteEngine On

RewriteRule ^/stores/([0-9]+)/?$                    /script.asp?id=$1
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Orodreth is offline
Reply With Quote
View Public Profile Visit Orodreth's homepage!
 
Old 06-28-2006, 11:36 AM Re: Creating virtual subdirectory
funkdaddu's Avatar
Web Design Snob

Posts: 635
Trades: 0
AFAIK .htaccess is only for Apache servers, I'm on IIS.

Last edited by funkdaddu; 06-28-2006 at 12:00 PM..
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Old 06-28-2006, 12:12 PM Re: Creating virtual subdirectory
Minaki's Avatar
Defies a Status

Posts: 1,626
Location: Guildford, UK
Trades: 0
Are you using .NET? You can use Incoming.RewritePath()
It's best to use it in the Application_BeginRequest() sub in Global.asax. You can read the incoming URL using HttpContext.Current.Request.Path - this will return a string such as "/stores/123456"

You then need a bit of code to work out where the request should be redirected, i.e. extracting the ID from that string... then you just call Incoming.RewritePath() passing in the new URL:
Incoming.RewritePath("script.asp?id=" + ID.ToString());


There's also an ISAPI DLL that someone has written to emulate .htaccess functionality. You'll need access to the server to install it though, I think.
__________________
Minaki Serinde MCP
"Wow, Linux is nearly on-par with Windows ME!"

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by Minaki; 06-28-2006 at 12:20 PM..
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
Old 06-28-2006, 12:56 PM Re: Creating virtual subdirectory
funkdaddu's Avatar
Web Design Snob

Posts: 635
Trades: 0
Quote:
Originally Posted by Minaki
Are you using .NET? You can use Incoming.RewritePath()
It's best to use it in the Application_BeginRequest() sub in Global.asax. You can read the incoming URL using HttpContext.Current.Request.Path - this will return a string such as "/stores/123456"

You then need a bit of code to work out where the request should be redirected, i.e. extracting the ID from that string... then you just call Incoming.RewritePath() passing in the new URL:
Incoming.RewritePath("script.asp?id=" + ID.ToString());


There's also an ISAPI DLL that someone has written to emulate .htaccess functionality. You'll need access to the server to install it though, I think.
Yes I'm using .Net. So I would put a Global.asax file in the /stores/ directory? I'm not too familiar with .Net, just old ASP+. I was looking at this way: http://www.4guysfromrolla.com/webtech/101701-1.shtml but when my host changed the 404 file it's not being rendered as ASP and it's not appending the 404'd url.

So would it be something like:
Code:
<script language="VB" runat="server">

Application_BeginRequest()

     storeUrl = "/stores/"

     if Left(HttpContext.Current.Request.Path,  Len(storeUrl)) = storeUrl then
         storeNum = Mid(HttpContext.Current.Request.Path, InStrRev(Request.QueryString, "/") + 1)
         Incoming.RewritePath("/locations/storedetail.asp?id=" + storeNum);
     end if
End Sub
</script>
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Old 06-28-2006, 05:22 PM Re: Creating virtual subdirectory
Minaki's Avatar
Defies a Status

Posts: 1,626
Location: Guildford, UK
Trades: 0
Nearly...

storeNum = Mid(HttpContext.Current.Request.Path, InStrRev(Request.QueryString, "/") + 1)

Should be:

storeNum = Mid(HttpContext.Current.Request.Path, InStrRev(HttpContext.Current.Request.Path, "/") + 1)

Global.asax should go in the root of the web application (it serves practicly the same purpose as global.asa in classic ASP).

Oh, another thing I just realised - I think you have to have the first (static) URL as an ASPX page, not a sub directory - otherwise IIS won't pass the request to the ASP.NET process. i.e. change /store/123456/ to /store/123456.aspx (and change the code to extract the ID accordingly)
__________________
Minaki Serinde MCP
"Wow, Linux is nearly on-par with Windows ME!"

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by Minaki; 06-28-2006 at 05:23 PM..
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
Reply     « Reply to Creating virtual subdirectory
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.26625 seconds with 12 queries