Objective: To mimic something of that of tinyurl but internally hosted, but not have that random text at the end of the url but be something that you can specify inside of a database.
Environment: OS = Windows 2003 , Service = IIS 6.0
Status: Currently have a working prototype but trying to make it work in a different way. Currently how it works is if the user goes to http://example.com/k.aspx?k=Books
, it then sees that the value of "k" is set to "Books" then connects to the MSSQL (KLinks) database and searches for an entry for "Books". If an entry is found for "Books" it grabs what the long url should be for that reference "TrueUrl". This "TrueUrl" for "Books" may be an entry like http://example.com/library/reference/clients/teachers/start/notes/books.html
, once it has grabbed this value from the database it will redirect (i don't care about rewrite) the user to the link http://example.com/library/reference/clients/teachers/start/notes/books.html
. So long story short when a user goes to http://example.com/k.aspx?k=Books
it connects to a database, looks up an entry for Books and redirects to http://example.com/library/reference/clients/teachers/start/notes/books.html
Where I'm stuck: So currently to use the script you have to use a link like http://example.com/k.aspx?k=Books
...but I want to be able to use it like this http://example.com/Books
So I've read to solve this i need to use the script as part of my 404 error and parse out the last part of of the query string to pull out the "Books" in a link like http://example.com/Books
. So the original script I've tested and works when using the link http://example.com/k.aspx?k=Books
I've set to be the 404 error page for that site.
Since the original script requires you to set the value of "k" to work, the script no longer works when it's set to the 404 error page.
I'm not very well versed in C# so a bit stuck on how to edit the existing script (Pasted in the Code Snippet) to be the 404.asp and parse out the the requested string and grab the last part of the link after the last "/".
A good example in asp that i found that is very similar to what I'm trying to do is below. (I can't seem to mimic this in C# in the script (in the code snippet)
----asp example start----
SomeDir = Request.ServerVariables("Q
SomeDir = UCase(Mid(SomeDir, InStrRev(SomeDir, "/") + 1, Len(SomeDir)))
'SomeDir now contains whatever the user typed after the last
'slash in the URL, if he typed http://www.foo.com/books
'will contain "BOOKS".
----asp example end----
Conclusion: Anyone able to show me how to edit the code in the snippet to work as a 404 error to redirect like the script i originally attached. I'm looking to no longer use http://example.com/k.aspx?k=Books
but instead have something like http://example.com/Books
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
protected void Page_Load(object sender, EventArgs e)
//URL used to enter:
String KValue = Request.QueryString["k"].ToLower();
//Open K database and pull
// all Active records
System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection("Data Source=MSSQL;Initial Catalog=K;Persist Security Info=True;User ID=IDGoesHere;Password=PasswordGoesHere");
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("SELECT TrueURL, KID FROM KLinks WHERE Active = 1", conn);
System.Data.SqlClient.SqlDataReader myReader = cmd.ExecuteReader();
//loop over all Active Records
Kid = myReader.GetString(1).Trim().ToLower();
URL = myReader.GetString(0).Trim().ToLower();
//if database key matches URL Parameter...
if (KValue == Kid)
//redirect to URL
<html xmlns="http://www.w3.org/1999/xhtml" >
The link you entered is invalid. Please check the source and try again.