Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I am trying to get an encrypted querystring on a ActionResult but the parameter is always null.

I have implemented an e-mail URL and encrypted some informations like this:

string key = "r0b1nr0y";
var queryString = EncryptDecryptQueryString.Encrypt(String.Format("testId={0}&otherInfo={1}", Id, otherInfo), key);

It is resulting in this URL parameter:

?fpZG2mFDOZbuuBFccKLeu9Rzbn/I05i577IaaMSt0uztuHmWdeVIOQ==

And the url is something like this:

www.test.com/MyController/MyAction?fpZG2mFDOZbuuBFccKLeu9Rzbn/I05i577IaaMSt0uztuHmWdeVIOQ==

Now, at the controller side, the ActionResult is suppose to receive a string.

Running the program, when i try to test the generated url, the code reach MyAction but the string parameter is always null.

public ActionResult MyAction(string queryString)
{
     ... Do Stuff here...        
}

I have tried to create a specific route for it as well(like this example), but didn't work.

routes.MapRoute(
            "RouteTest",
            "MyController/MyAction/{queryString}",
            new { controller = "MyController", action = "MyAction", queryString = "" }
        );

I can take the whole url with Request.RawUrl, but i really can't understand why the encrypted string parameter is null(or empty).

Have i missed the point somewhere or is there an explanation for the null parameter value?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

First of all you need to UrlEncode that Base64 string because "/" and "=" have special meaning in your URL.

Second: Without the routing your URL should be: www.test.com/MyController/MyAction?queryString=[UrlEncodedBase64] With a query string parameter that would match the parameter name of your action.

share|improve this answer
    
i got the idea, this workaround worked for me. – Maturano 12 hours ago

It is null because your method is expecting your url to end with:

?queryString=xxxxxxxx

I understand your approach, but you'll either have to encrypt all the parameters separately, use the approach I've shown above, or write your own model binder for the method that can interpret what's in the URL for your code to consume.

Model binders: https://msdn.microsoft.com/en-us/library/dd410405(v=vs.100).aspx

share|improve this answer
    
thanks for replying. Yes i was forgetting to include the "queryString" before the encoded queryString, – Maturano 12 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.