[MVC] How to fix the bug that missing plus in request. querystring/Form

Source: Internet
Author: User

Recently, we were working on Data Interconnection with a company. Our technical staff observed that some of the data could not be verified by MD5 encryption.

OriginalCodeAs follows:

1 [Httppost]
2 Public Actionresult index ( String Lcdata)
3 {
4 String Lcdatadecode = httputility. urldecode (lcdata, encoding. utf8 );
5 String Response = dosometing (lcdatadecode );
6
7 Return Redirecttoaction ( " Index " );
8 }

Through data comparison between the two parties, it is found that the lcdata value in the above Code is a value after the decode, not the original data. Due to this decode, the plus sign "+" in the data is filtered out.

See Dudu'sArticleDistinction and Application of httputility. urlencode, httputility. urldecode, server. urlencode, and server. urldecode

Some solutions have been found on the Internet.Request.Querystring["Key"].Replace("", "+");. However, our data cannot be processed in this way, because the transmitted data contains a space.

Therefore, we found the following method:

1 [Httppost]
2 Public Actionresult index ( String Lcdata)
3 {
4 RegEx r = New RegEx ( @" Lcdata = (? <Value> [^ & =] +) " ); // For our needs, if we need to resolve all (? <Name> [^ & =] +) = (? <Value> [^ & =] +)
5 Match m = R. Match (request. Params. tostring ());
6
7 Lcdata = M. Groups [ 1 ]. Value;
8 String Lcdatadecode = httputility. urldecode (lcdata, encoding. utf8 );
9
10 String Response = dosometing (lcdatadecode );
11
12 Return Redirecttoaction ( " Index " );
13 }

Hope to help other friends in need.

 

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.