【问题标题】:asp.net core uri encodeasp.net 核心 uri 编码
【发布时间】:2018-12-11 06:57:48
【问题描述】:

我在 asp.net core 中有类似的东西(我正在使用 asp.net core c# using razor):

@Html.ActionLink("Edit", "EditEmployee","Employee", new { id = item.id})

这个item.id是base64string,它将在中间层解码,它在编码字符串中有斜杠('/')字符,所以action无法理解它并且action参数为null。

我的问题是如何将此 item.id 发送到我的操作,因为它是包含斜杠('/')的 base64string。

这是我在 startup.cs 中的地图路线:

routes.MapRoute(
       name: "EditEmployee",
       template: "{controller=Employee}/{action=EditEmployee}/{id?}");

这是我需要调用的操作...但是双斜杠参数正在变为空。

    [HttpGet]
    [ActionName("EditEmployee")]

    public async Task<IActionResult> EditEmployee(string id)
    {
        if (!string.IsNullOrEmpty(id))
        {   
            var result = await _accountAction.GetEditEmployee(id);

            if (result.Item1)
            {
                return View(result.Item2);
            }

        }
        return RedirectToAction(nameof(ListEmployee));
    }

【问题讨论】:

  • 加密工作正常,但我的控制器不接受这个多斜线数据作为参数。
  • 我的意思是为什么不使用WebUtility.UrlDecode,将你的cshtml行改为这个-@Html.ActionLink("Edit", "EditEmployee","Employee", new { id = System.Net.WebUtility.UrlDecode(item.id) })

标签: .net-core urlencode


【解决方案1】:

我会在保存之前简单地从字符串中删除“/”、“=”和“+”符号。

【讨论】:

  • 这是不可能的,因为这些特殊字符出现在随机位置,并且是需要发送到业务层的加密数据
  • 哦抱歉,我没有意识到这是加密数据。你可以查看 Base58
猜你喜欢
  • 2018-01-27
  • 1970-01-01
  • 1970-01-01
  • 2017-10-23
  • 1970-01-01
  • 1970-01-01
  • 2020-11-01
  • 2021-09-21
相关资源
最近更新 更多