0

I have One conroller method like

public ViewResult MyMethod(long id, string pId)
{

}

I have one query string like

?'id=' + 10 + '&pId=' + 15

I want to encrypt it using some encryption algorithm after that i got query sting in some format like

gaiSXZyTAq6Z0a5TzsrdG2LjIj0moe2m4D0qQiG7zuQ=

I am decrypting it from Global.asax in begin Request, Able to decrypt and setting Query string All Keys but controller not able to get its parameter value

  protected void Application_BeginRequest(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Convert.ToString(Request.QueryString)))
            {
                var newQueryString = SecurityEncryption.DecryptionValue(HttpUtility.UrlDecode(Convert.ToString(Request.QueryString)).Replace(" ", "+"));
                Request.QueryString.AllKeys[0] = newQueryString;

            } 
        }

I want that Controller Method will get its Parameter values,How can I achieve this?

Please any one can help me.

4
  • possible duplicate of stackoverflow.com/questions/603092/… Commented Jun 14, 2014 at 6:59
  • 1
    @NachoLaborde That question is in asp.net and i am asking it in Asp.net MVC and here i want to get something like intermediate which converts my encrypted query string in original format and also my controller method get those parameters too. Commented Jun 14, 2014 at 7:13
  • Ok, you can create an attribute like this dotnettrace.net/2013/09/encrypt-and-decrypt-url-in-mvc-4.html Commented Jun 14, 2014 at 7:25
  • @NachoLaborde Thanks for Link, Let me check Commented Jun 14, 2014 at 7:29

2 Answers 2

0

I found sollution I decrypt my base controller

public override void OnActionExecuting(ActionExecutingContext filterContext)
 {
     var queryStringQ =  Server.UrlDecode(filterContext.HttpContext.Request.QueryString["q"]);
 if (!string.IsNullOrEmpty(queryStringQ))
        {
            // Decrypt query string value
            var queryParams = DecryptionMethod(queryStringQ);
        }
 }
Sign up to request clarification or add additional context in comments.

1 Comment

Where did you put this, in the globax.asax file?
0

Yes we are able to fix global.asax

protected void Application_BeginRequest(object sender, EventArgs e)
{
    if (!string.IsNullOrEmpty(Convert.ToString(Request.QueryString)))
    {
        var newQueryString = SecurityEncryption.DecryptionValue(HttpUtility.UrlDecode(Convert.ToString(Request.QueryString)).Replace(" ", "+"));
 
        PropertyInfo isreadonly = typeof(System.Collections.Specialized.NameValueCollection).GetProperty("IsReadOnly", BindingFlags.Instance | BindingFlags.NonPublic);
        isreadonly.SetValue(this.Request.QueryString, false, null);
        this.Request.QueryString.Set(queryString, newQueryString );
        isreadonly.SetValue(this.Request.QueryString, true, null);
    } 
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.