如何加密&解密mvc3中的整个URL或URL参数?

时间:2014-05-30 07:30:35

标签: asp.net-mvc-3 encryption

return RedirectToAction("deshboardportal", "Portal",new { User_Id = Session["USER_ID"], RoleId = Session["ROLE_ID"]});

在上面的代码中,我只想加密下面写的url参数: -

new { User_Id = Session["USER_ID"], RoleId = Session["ROLE_ID"]}

1 个答案:

答案 0 :(得分:0)

你可以尝试

 return RedirectToAction("deshboardportal", "Portal", new { User_Id = Encode(Session["USER_ID"].ToString()), RoleId = Encode(Session["ROLE_ID"].ToString()) });



  public string Encode(string encodeMe)
        {
            byte[] encoded = System.Text.Encoding.UTF8.GetBytes(encodeMe);
            return Convert.ToBase64String(encoded);
        }

        public static string Decode(string decodeMe)
        {
            byte[] encoded = Convert.FromBase64String(decodeMe);
            return System.Text.Encoding.UTF8.GetString(encoded);
        }