Querystring issue

25 views
Skip to first unread message

wswelch

unread,
Aug 26, 2007, 10:34:43 PM8/26/07
to UrlRewritingNet
Hello, I have gotten this http module working, and configured IIS so
that I can use URLs without an extension. I am experiencing a few
issues however. First, regardless of whether I use an extension or
not, once I navigate to a virtual URL and I click a button that causes
a postback, I then get the querystring added to my virtual url in the
address bar. For example:

My virtual URL: http://www.domain.com/cats/8/
redirected URL: http://www.domain.com/products/subcats.aspx?catid=8

After I cause a postback the URL in my address bar looks like this:

http://www.domain.com/cats/8/?catid=8

and the value of catId on the server is "8,8", which doesn't work well
for me.

The other issue I am getting is that when I do not use an extension I
am getting a javascript error. The only difference in the source of
the page that I see is that the form action is empty.

Any help would be much appreciated. Thanks.

ball...@gmail.com

unread,
Sep 14, 2007, 5:30:29 AM9/14/07
to UrlRewritingNet
I believe I have the same problem, but a come accross it
differently...

In my case I have say a public member profile which you can get by
mysite.com/members/username.aspx which translates to mysite.com/
profile.aspx?mem=username. This works fine.

Now in that page I have a button, say "Add to friends", which when
clicked, checks that the visitor is logged in and if not, redirect to
a log in page, where once logged in sends them back to the profile
page where they can add the member as a friend.

The problem I encounter is that when I detect that they are not logged
in, I send them to the log in page and my ReturnURL is determined by
using HttpContext.Current.Request.Url.PathAndQuery. Which turns out
to look like: ReturnURL=/members/username.aspx?mem=username. As you
can tell, this causes the same problem as the first post, where
"username" would appear twice in the mem parameter
"username,username".

I was planning on doing a hack and see if the username appears twice
on the querystring and if so, only use the first username. But I have
to many differnt rules where this can happen and it does not seem
safe.

The only way I can think of correctly fixing this is to determine if
the URL is a rewritten URL:

if ( rewritten ) then
redirect ( ReturnURL=Request.Url.LocalPath ) 'Since it IS a rewritten
URL, do not include the QS
else
redirect ( ReturnURL=Request.Url.PathAndQuery ) 'Since it is not a
rewritten URL, include the QS as the return
end if

I tought I would be able to do this by doing:

If (rule.IsRewrite(Request.Url.LocalPath)) Then

but I think this is only if you write your own provider. Is there any
way to use the default provider and call it's IsRewrite method????

Please let me know. Thank you!

- Andy

ball...@gmail.com

unread,
Sep 14, 2007, 11:43:06 AM9/14/07
to UrlRewritingNet
I think I came up with a solution.

Using the code provided, I found the Init in the URLRewriteModule
which was doing what I basically needed. What I ultimately ended up
doing was looping through each rewrite and then testing if the current
page satisfied a rewrite rule, if it did, then redirect without the
querystring, otherwise, include the querystring.

I'm not sure how efficient this is, but this will only be called if
they try to perform an action which requires they be logged in AND
they are not logged in, so it's not that frequent (in comparison to
each request)

Private Shared Function URLRewritten(ByVal LocalPath As String) As
Boolean
Dim ruleFound As Boolean = False
For Each rewriteSettings As
UrlRewritingNet.Configuration.RewriteSettings In
Web.UrlRewriting.Configuration.Rewrites
Dim rewrite As RewriteRule = Nothing
Dim providerName As String = rewriteSettings.Provider
If (String.IsNullOrEmpty(providerName)) Then
rewrite = UrlRewriting.CreateRewriteRule()
Else
rewrite = UrlRewriting.CreateRewriteRule(providerName)
End If
rewrite.Initialize(rewriteSettings)

If (rewrite.IsRewrite(LocalPath)) Then
ruleFound = True
Exit For
End If
Next
Return ruleFound
End Function


If (URLRewritten(HttpContext.Current.Request.Url.LocalPath))
Then

HttpContext.Current.Response.Redirect(FormsAuthentication.LoginUrl & "?
ReturnUrl=" &
HttpUtility.UrlEncode(HttpContext.Current.Request.Url.LocalPath)
Else

HttpContext.Current.Response.Redirect(FormsAuthentication.LoginUrl & "?
ReturnUrl=" &
HttpUtility.UrlEncode(HttpContext.Current.Request.Url.PathAndQuery)
End If

Please let me know if there is a better way of doing this. Otherwise,
hope this helps someone.

> > Any help would be much appreciated. Thanks.- Hide quoted text -
>
> - Show quoted text -

Reply all
Reply to author
Forward
0 new messages