C Sharper
C Sharper

Reputation: 8626

url encode component not getting in string server side

I have # in my string.

and i am sending that string to my c# method on server side through ajax.

I am sending it as follows:

$.ajax({
type: "POST",
url: "http://localhost:5889/MobileEcomm/Service1.svc/validateLogin/"+EmailID+"/"+encodeURIComponent(Password),
crossDomain: true,

success: function (data) {

    alert(JSON.stringify(data));
     alert("Login Sucessfull!!!");   
        window.location = "viewOrders.html";

    // do something with server response data
},
error: function (err) {
    // handle your error logic here
    alert("Error");
}

});

my Password string is : pass@#

My c# method structure:

public string validateLogin(string Email, string Password)
        {
              return Password;
        }

Wheni get password parameter in c#, Its as follows:

pass@

When i make alert of

encodeURIComponent(Password)

Its:

pass%40%23

Why i am not getting same result (pass%40%23) as a parameter for password in my c# method???

Plaese help me.

Upvotes: 2

Views: 635

Answers (1)

Mohit
Mohit

Reputation: 2217

If you are hosting your WCF Data Service on top of IIS+ASP.Net/WCF, then you may discover that there are certain characters that will cause the server to throw when they are contained in entity keys. The result is either a 400 Bad Request or 404 Not Found. In VS 2010 RC, you can potentially configure the server to support these characters, but first, let’s see what characters are considered “special”:

%,&,*,:,<,>,+,#, /, ?,\

If any of the above characters are used inside a string key for an entity, then querying for the entity will resulting in an error, whether you escape the Uri or not.

And you are using # in the URL so that's why it is not providing proper result.

check this link for solution on MSDN blog

http://blogs.msdn.com/b/peter_qian/archive/2010/05/25/using-wcf-data-service-with-restricted-characrters-as-keys.aspx

you might also like to see this link as well, it will answer your second part of question why you are getting %40%23 as values.

https://social.msdn.microsoft.com/Forums/vstudio/en-US/d03c8331-1e98-4d5d-82a7-390942a93012/special-characters-in-wcf-rest-atom-feed?forum=wcf

Upvotes: 2

Related Questions