How does Asp.net use Chinese characters, spaces, and special characters in URLs?

Source: Internet
Author: User

When creating a link in cshtml or aspx/ascx, if the parameter may be Chinese, you need to use httputility. urlencode ():

 
@ Html. Link ("role", "/SFC/users/users2roles? User = "+ httputility. urlencode (user. Identity. Name ))

In the corresponding action, everything is as usual and there is no "decode" (there are also posts saying yes, but I do not need the results of my experiments ):

 
Public actionresult users2roles (string user) {viewbag. user = user; return view (sfcroles. getallroles ();} [httppost] public actionresult users2roles (string user, formcollection collection) {viewbag. user = user; try {}}

In addition, it can solve the problem of space and special characters. For example, if you want to close a page and return to another page, but there are more than two links to the other page, therefore, if there is an "&" in it, you can: use:

 
@ Html. Link ("X", "/SFC/categories/delete? Rootid = "+ root. ID +" & id = "+ model. ID, showinnewwindow: false, returnurl: httputility. urlencode (request. url. tostring ()))

This html. link is a self-compiled helper. If you use a directly, the same is true.

But this write to write after all too long too much trouble, so if you often use returnurl please refer to my other post: http://blog.csdn.net/cheny_com/article/details/6544338 in the last few lines supplement. The two problems come together.

Refer:

Http://stackoverflow.com/questions/3101823/extract-chinese-text-from-query-string

Http://stackoverflow.com/questions/1380617/request-url-parameter

Http://stackoverflow.com/search? Q = Chinese + parameter + URL + Asp.net (all similar problems in stackoverflow)

 

Click to download the free agile development textbook: Martian agile development manual

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.