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.

Sid
  • 801
  • 8
  • 19
  • possible duplicate of http://stackoverflow.com/questions/603092/how-to-pass-encrypted-query-string-in-asp-net – Ignacio Laborde Jun 14 '14 at 06: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. – Sid Jun 14 '14 at 07:13
  • Ok, you can create an attribute like this http://www.dotnettrace.net/2013/09/encrypt-and-decrypt-url-in-mvc-4.html – Ignacio Laborde Jun 14 '14 at 07:25
  • @NachoLaborde Thanks for Link, Let me check – Sid Jun 14 '14 at 07:29

2 Answers2

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);
        }
 }
Sid
  • 801
  • 8
  • 19
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);
    } 
}
Bamdad
  • 726
  • 1
  • 11
  • 28