Mvc中url地址栏base64加密

Mvc中url地址栏base64加密

1.引用base64.js
eg:
 <script src="~/js/base64.js"></script>
2.前台页面上
eg:
 <button  class="btn" οnclick="cmdEncrypt()">登录</button>
eg:
<script>
    function cmdEncrypt() {
        if (confirm("亲!确认好信息了么?")) {
            var promotion_price = $("#promotion_price").val();
            var departure_city = $("#departure_city").val();
            var travel_dates = $("#travel_dates").val();
            var number_of_travel = $("#number_of_travel").val();
            var loadline = $("#loadline").val();
        
            var b = new Base64();
            var params = {};
            params.promotion_price = b.encode(promotion_price);
            params.departure_city = b.encode(departure_city);
            params.travel_dates = b.encode(travel_dates);
            params.number_of_travel = b.encode(number_of_travel);
            params.loadline = b.encode(loadline);
     
            location.href = "/Order/Shopping?promotion_price=" + params.promotion_price + "&departure_city=" + params.departure_city + "&travel_dates=" + params.travel_dates + "&number_of_travel=" + params.number_of_travel + "&loadline=" + params.loadline;
 
        }
        else {
            return false;
        }
     
    }</script>
4.后台
eg:
 //加密
        public static string DecodeBase64(Encoding encode, string result)
        {
            string decode = "";
            byte[] bytes = Convert.FromBase64String(result);
            try
            {
                decode = encode.GetString(bytes);
            }
            catch
            {
                decode = result;
            }
            return decode;
        } 
        //
        // GET: /Order/
        //填写详情并下单
        public ActionResult Shopping()
        {
            string loadline1 = Request["loadline"];
            string promotion_price1 = Request["promotion_price"];
            string departure_city1 = Request["departure_city"];
            string travel_dates1 = Request["travel_dates"];
            string number_of_travel1 =Request["number_of_travel"];
     
            string loadline = DecodeBase64(Encoding.UTF8, loadline1);
            string promotion_price = DecodeBase64(Encoding.UTF8, promotion_price1);
            string departure_city = DecodeBase64(Encoding.UTF8, departure_city1);
            string travel_dates = DecodeBase64(Encoding.UTF8, travel_dates1);
            string number_of_travel = DecodeBase64(Encoding.UTF8, number_of_travel1);
        

            ViewBag.promotion_price = promotion_price;
            ViewBag.departure_city = departure_city;
            ViewBag.travel_dates = travel_dates;
            ViewBag.number_of_travel = number_of_travel;
            ViewBag.loadline = loadline;
            return View();
        }












  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值