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.
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
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 -