My querystring parameter continuously appear - asp.net

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

Related

How to get only contents of the browser address bar, NOT full URI

Does anyone know if there's a clean way to get the contents of the browser address bar, not the absolute URI?
I know you can use Request.Url.AbsoluteUri to get the full request, and normally that would be fine. However, in this case I need to know if the user has landed on the page via the site's basic DNS.
For example, if my site is called http://www.mysite.com, and the default page is page1.aspx, then Request.Url.AbsoluteUri returns http://www.mysite.com/page1.aspx if a user hits the site from http://www.mysite.com. In this case, all I want to get is: http://www.mysite.com. Is this possible?
The reason behind this is so that I can have the site embed statistical JavaScript code on the root page if the site is hit via the basic URL, and not if the page is included in the address bar. Does this make sense?
The term you are looking is URL ReWriting
Refer this tutorial

urlrewrite.Net Infinite Loop

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.

Google Chrome and Response.RedirectPermanent

I just ran across a problem that took a little while to figure out and wanted to document it for someone else that may have the same issue.
Our site can be used in different countries, so we have URLs that look like this:
http://www.example.com/
http://www.example.com/CA
http://www.example.com/UK
The first automatically goes to the US. We use a cookie to remember their country so that when they come back to the site later (http://www.example.com), we redirect them to (http://www.example.com/CA)
When someone wants to go back to the US version, they click a link like this (http://www.example.com/US) which sets their cookie and redirects back to the main site because the US one normally doesn't have the country code.
In doing these redirects, we would do the following if they clicked the /US link:
SetCookie("US");
Response.RedirectPermanent("/");
The problem came when they switched to Canada (which worked) and then tried to switch back to the US. Answer below.
The problem came with Google Chrome. Because we used a permanent redirect, it would not even send http://www.example.com/US to the browser. It said basically:
Oh, last time they told me /US is a
permanent redirect to / so I'll just
request / without sending /US to the
browser.
So the fix was to use Response.Redirect (302) instead of Response.RedirectPermanent (301).

How to get last refrer Url in Asp.net

I have found problem in my code. I am working on facebook application. and May be facebook made some changes so I got struck. Everything was working fine till yesterday. But from today it's not working.
Issue that what i found is. Earlier I was managing last refer url for some task. But its format get changed. Now it's not working.
Last refer URL is
http://apps.facebook.com/mycurrentfollower/?session={%22session_key%22%3A%221fd7d4189b8eded157c4a173.0-100000086206090%22%2C%22uid%22%3A%22100000086206090%22%2C%22expires%22%3A0%2C%22secret%22%3A%2226e9d307ff4038173e966d881faf0c97%22%2C%22access_token%22%3A%22194311980605862|1fd7d4189b8eded157c4a173.0-100000086206090|YmiFbTAucSZ-TvkCA6QZVUw4-8M%22%2C%22sig%22%3A%222c6a9973a4dd868744d712d919a2b937%22}
But when I am trying to fetch last refer url like
Uri requesturl = Request.UrlReferrer;
I am only getting this Part
http://apps.facebook.com/mycurrentfollower/
And this is also my current URL.
How Can I get rest of url. Please let me know. I trried lot of thing but nothing is working.
Thanks
hey i think this will help you
Request.UrlReferrer.PathAndQuery

Url Encoding in MVC

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.

Resources