How to convert URL spaces in the Web

Source: Internet
Author: User

The URL is HttpUtility. UrlEncode, which converts the space to the "+" number. If you find the cause, you can solve the Bug.
Reference:
Copy codeThe Code is as follows:
FileName = HttpUtility. UrlEncode (fileName, Encoding. UTF8 );
FileName = fileName. Replace ("+", "% 20 ");

It is solved through Replace replacement. Although the problem is solved, this is not a good method. If the folder or file name contains the "+" number, it will lead to another Bug.
Best Solution:

Use HttpUtility. UrlPathEncode and UrlPathEncode to perform the following steps:

1. Apply the encoding logic of the UrlPathEncode method only to the URL path section (excluding the query string ). This method assumes that the URL is encoded as a UTF-8 string.

2. Non-space encoding to use a subset of the first 128 ASCII characters in the resulting encoding string. All characters in Unicode are 128 or higher, or 32 or smaller, and are entered in the URL.

3. Enter a space as % 20.

You can enter a URL using the UrlEncode or UrlPathEncode method. However, the method returns different results. The UrlEncode method converts each space character to the plus sign (+) character. The UrlPathEncode method converts each space character into a string % 20, representing a space in hexadecimal notation. The UrlPathEncode method is used to partially encode the URL path to ensure consistent decoded URLs, regardless of the platform or browser that performs decoding. When you use the UrlPathEncode method, the query string value is not input. Therefore, you can use any question mark value (?) In the string, no input will be made. If the URL is required, the UrlEncode method is used when the string is queried.

Many pages in the project use the Replace method. After the query, Replace all the pages with UrlPathEncode to reduce the occurrence of more bugs.

Related Article

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.