简体   繁体   中英

ampersand url encoding issues

I'm hard coding a url to have something like this:

"/ContactUs.aspx?mode=New&form=Contact"

the page is rendering the below as part of the url...

mode=New&amp%3bform=Contact

so the page breaks when i rediriect to this page. and try to Request.QueryString["form"].

how can i make it behave with the & symbol

Have you tried escaping the ampersand using the HTML entity & ? Ampersands in URLs must be escaped. You should also URL Encode any values passed in the query string - I think HttpUtility.UrlEncode() does that (off top of my head).

For instance, your URL should be:

/ContactUs.aspx?mode=New&form=Contact

However, you don't need to do this if you are using an <asp:HyperLink /> , as NavigateUrl properties are automatically encoded.

See this article on URL Encoding for why you need do this. In .NET you can use the HttpUtility.UrlEncode method to do this. This is also accessible via Server.UrlEncode of current HttpContext.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM