views:

40

answers:

0

Hi there,

I'm trying to implement URL Rewriting into my existing application and have managed to get the page and links working except that my destination page does not get the query string values.

My code is based on the example below:

http://dotnetguts.blogspot.com/2008/07/url-rewriting-with-urlrewriternet.html

Basically I have a default.aspx page with links to another page;

directory_item.aspx?Item_Id=1&Category_Id=1
directory_item.aspx?Item_Id=2&Category_Id=1 and so on...

The code in my web config is as follows;

< rewriter >
   < rewrite url="~/(.+)-(.+).aspx" to="~/directory_item.aspx?MyTitleItem_Id=$2" / >
< /rewriter >

As for the function mentioned at the above website link, I changed it to accommodate my Category Id as well;

Public Shared Function GenerateURL(ByVal Title As Object, ByVal strId As Object, ByVal strCategoryId As Object) As String
   Dim strTitle As String = Title.ToString()
   ...
   ...

   ...

   'Append ID at the end of SEO Friendly URL
        strTitle = "~/" & strTitle & "-" & Convert.ToString(strId) & "-" & Convert.ToString(strCategoryId) & ".aspx"

   Return strTitle
End Function

On my Page Load of directory_item.aspx I look for the query string values Item_Id and Category_Id and since I've implemented the above the page only returns a blank page with no data? I am missing something and just don't know where? Any help will be appreciated.

The URL does get changed to ' the-title-page-2-1.aspx ' and it load the styles and everything except for the data. So there must be something small wrong with my code.

What I've discovered so far;

By changing the code in web config file I got it to work; except that I now need to pull in the second query string parameter;

url="(.+)-(.+).aspx" to="~/directory_item.aspx?Item_Id=$2"

Any tips on how I can get the second query string parameter to work? Thanks