Im using urlrewrite.net # http://urlrewriter.net to perform url rewrites on a .net website hosted on a Windows 2003 server with IIS 6.
I need to simply turn a long dynamic url such as:
http://mydomain.com/aircraft/result.aspx?view=,734,,810,,159,,163&cat=1&loc=999999&model=false
into a shorter friendlier url such as:
http://mydomain.com/forsale/manufacturer/,734,,810,,159,,163,/1/999999/false
I have the following rule in my web.config:
<rewrite url="^/forsale/(.+)/(.+)/(.+)/(.+)/(.+)" to="/aircraft/result.aspx?view=$2&cat=$3&loc=$4&model=$5" / >
This works fine when I enter the following as the url:
http://mydomain.com/forsale/manufacturer/,734,,810,,159,,163,/1/999999/false
However, as soon as I trigger any sort of postback it enters an infinite loop and the url in the browser address bar goes all crazy eg:
http://mydomain.com/aircraft/result.aspx?view=1&cat=999999&loc=detailed.aspx?AId=32270&Cat=Business-Jets&seo=Bombardier&model=Challenger%20300&cat=1&cat=1&cat=1&cat=1&cat=1&cat=1&cat=1&cat=1&cat=1&cat=1&cat=1&cat=1&cat=1&cat=1&cat=1&cat=1&cat=1&cat=1&cat=1&cat=1
It seems to be reverting to the real url but adding duplicated querystring variables..
Ideally I would like this to maintain the shorter/friendlier rewritten url but this isnt crucial. The main aim is to be able to actually allow postback events so that the page is fit for purpose.
Any help / suggestions / pointers / answers will be greatly appreciated!
Thanks in advance.
The infinite loop was due to a bit of redirect code on the page which was only causing an issue when accessed in this way. Removing it has solved the loop issue but has caused the real querystring to be appended on the rewrite url.
Related
I have a web app and i use the rewrite function for the URL. Here my sample URL:
www.mywebsite.com/oscar
It will bring the guest to www.mywebsite.com/User.aspx?blk=oscar
Everything is going fine until I realized that sometimes, I don't know why, every time my webpage do the post back, it will append the querystring into current URL. So the URL will be like this:
www.website.com/oscar&blk=oscar&blk=oscar&blk=oscar
anybody have the same experienced? please help me with your solution
I have spent about 7 hours trying to figure this out but gotten nowhere.
This is how my fiddler trace looks like
I have two routes that look like below that are registered for this page.
[route name="DummyResultsWithMarketStateNames" url="DummyResults/state-{statename}/market-{marketname}/page-{page}/{action}"
controller="DummyResults" action="Show"/]
[route name="DummyResultsWithMarketId" url="DummyResults/market-{marketid}/page-{page}/{action}"
controller="DummyResults" action="Show"/]
For this url, the first route matches and it goes to the right action. However, the client is sending in another request a second later in which it removes the last parameter 'page-1' and replaces it with 'none'. I've traced for XHR's and there are none. I'm not sure if this is an issue with the MVC framework itself but how would that translate as a request from the client?!!! Also, I'm getting different behavior with different browsers (IE trace above). Anyone encountered such strange behavior? I'd be happy to provide more info if you'd like.
UPDATE:
I setup the site on IIS and eliminated all image, css or script requests. I still end up with multiple requests. The original dummyresults page seems to be working now after I removed the .htc's. However, I have another page (screenshot below) that is not 'co-operating'. Should I add Ignoreroutes for certain extensions? This is driving me nuts!!! Pardon the 'bleep' on the image (IP reasons). PS: I setup another site for serving up all static resources.
Q: Should I add Ignoreroutes for certain extensions?
A: Of course! By default the WCF extension "*.svc" is ignored. The first thing I add on a ne page is for instance the ignore rule for the favicon.ico.
RouteTable.Routes.IgnoreRoute("*.svc");
RouteTable.Routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
RouteTable.Routes.IgnoreRoute("favicon.ico");
In my asp.net 2005 app, I would like conceal the app structure from the user. Currently, the end user can learn intimate details of my web app as they navigate and watch the url change. I don't want the end user to know about my application structure. I would like the browser url to not change if possible. Please advise.
thanks
E.A.
URL rewriting is the only one that can provide any kind of real concealment.
Just moving the requests to AJAX or to frames, means anyone (well, more advanced users) can still see those requests being fired, just not in the address bar.
Simplest solution is to use frames - a single frame that holds your application and is 100% * 100%. The URL will not change though the underlying URL can still be seen via "View Frame info", however only advanced users will even figure that out.
In your pages, make sure that they are contained inside the holding frame.
A couple of possibilities.
1) use AJAX to power everything. This will mean that the user never leaves the home page
2) use postbacks to power everything. In this, you'd have all those pages be user controls which you progrmattically hide or show.
3) URL rewriting (especially if this is asp.net 3.0 or later)
My site uses url parameters to dynamically load ascx files into a single main aspx. So if I get 'page_id=123' on the query string, I load the corresponding ascx. The url changes, but only the query string - the domain part remains the same.
If you want the url to remain precisely the same at all times, then frames (per Oded) or ajax (per Stephen) are probably the only ways to do it.
Short answer: use URL encryption
A simple & straight article: http://devcity.net/PrintArticle.aspx?ArticleID=47
and another article: https://web.archive.org/web/20210610035204/http://aspnet.4guysfromrolla.com/articles/083105-1.aspx
HTH
I am confused about what is supposed to be encoded and when and when it gets decoded. For example:
<%=Html.ActionLink("Login","Login",
new {controller="Account", returnUrl=HttpContext.Current.Request.RawUrl})%>
on the login page the address will be as follows:
/Account/Login?returnUrl=%2FPreviousDirectory
suddenly this will not take me back after filling in credentials and instead takes me to root directory. however, it was working fine before.
My question is regarding the "%2F". Is this the default behavior or did I mess something up? Does this need to be decoded?
This answer should show you how to do it.
This is actually a follow up on my previous question (link)
I've created the HttpHandler and it works fine for now, I'll add flexibility by using the querystring and session to point the post I'm making in the right direction.
The next question is as follows.
Now that I have the old page iframed as it should be, there's still the trouble of handling the postbacks (or actions) these pages trigger.
Every button action (asp form post) refers to a page that is not there (it's on the other server from which I am importing functionality).
I've tried using a url mapping to the other server but I get an error that tells me the external link is not a valid virtual directory. Hence I discarded this option.
I there anyway to keep functionality going inside the iframe?
please do ask clarification if you need it.
I got a solution from a colleague.
before passing the response string to the Iframe from the handler I use a string.replace to adjust the urls in the old site. This way they point to the old site and everything works again :)