URL rewriting, help required

I need some help here. For a web application I needed to use URL rewriting to create some nice easy to remember addresses.

Everything's fine except for some controls. I have on this page a Search textbox, so the user can enter a text and I send him to a search results page.

Very trivial, but with URL rewriting, according to this excellent article, you need to override the form tag to make things working properly.
So I used the assembly provided with the article, and actually only the method GET works. The POST method don't fire any events and send me back a 405 error.

I would be happy with the GET method, but of course this send all data as a query string, destroying all the efforts to make the URL nice and tidy.

Anyone has a solution ?

 

5 Comments

  • I'm not 100% sure if this is your problem, but something I encountered when doing this was a problem wit the action property of the form element.



    If the user requested login.aspx which rewrote the request to default.aspx, the form would look something like:

    <form method="post" action="default.aspx"...> when it should, in reality point to login.aspx. The problem is that you can't [easily] change this behaviour, even by creating your own class which inherits from HtmlForm since the action property is internally built and not overriable.



    The solution is to rewrite the URL to the origianl request via:

    Context.RewritePath(Path.GetFileName(Request.RawUrl))



    you can see this work in the community starter kit's communityDefault.aspx which does all the processing (ie, is where all original context.rewritepath's occur).



    Karl

  • Thanks for your comments and help :-)



    Well what I am trying to do is to apply the article by Scott Mitchell. Everything works well except the change he recommend to do to remove the action attributes. So I used the nifty Actionless dll and the new custom form tag. But everytime I try to use a Post method I have immediately after a button click this 405 authentication request error. My understanding on the error is the fact the method is not accepted. A Get method works fine except that I have now this ugly querystring with ll the view state details and other useless stuff.

    Any idea ?

  • Sorry the exact error is HTTP 405 - Resource not allowed

  • Paschal, IIS will not allow POST requests to a default document, which is what you're experiencing.



    If you really want to do URL rewriting you have to use an ISAPI filter, that will intercept the request before it's dispatched by IIS, it's a pretty trivial code (mine's about 200 lines of C++ right now), e-mail me at jerryiii at hotmail, I can share it... There's couple features that would need to be added for it to be a full blown rewriter but it's good enough for most applications.

  • The font of your blog is really really bad to read (at least in my FireFox through 256 color Remote Desktop connection...)

Comments have been disabled for this content.