【问题标题】:How to do Base64 Encoding while posting a html form?发布 html 表单时如何进行 Base64 编码?
【发布时间】:2017-06-08 05:42:56
【问题描述】:

我被困在一个地方,我需要将发布的 URL 编码为 Base64,同时将表单发布到 cshtml 页面中。我们在表单元素中确实有 enctype 属性,我们可以在其中获得 3 种编码,但是由于某些客户端要求,我们需要在 Base64 中对 URL 进行编码。以下是表单元素:

<body onload="document.getElementById('idPost').submit()">
    <form id="idPost" method="post" action= @System.Configuration.ConfigurationManager.AppSettings["postUrl"]
        style="margin: 0; padding: 0;">
        <fieldset style="border: 0">
            <h3 style="text-align: center;">We Are Signing You In, Please Wait...</h3>

            @Html.HiddenFor(model => model.agent);
             @Html.HiddenFor(model => model.User_ID);
            @Html.HiddenFor(model => model.Password);
            @Html.HiddenFor(model => model.errorUrl);
            @Html.HiddenFor(model => model.originalResourceUri);

        </fieldset>
    </form>
</body>

我们将不胜感激。

【问题讨论】:

  • 在行动部分??我的意思是说@System.Configuration.ConfigurationManager.AppSettings["postUrl"],这个??如果是,那么您可以使用 Convert.ToBase64String() 但我想知道您将如何对其进行解码以便调用适当的操作。
  • @SubhabrataMondal:实际上我希望将完整的发布 URL(以及所有隐藏字段)编码为 base64。

标签: javascript c# jquery html forms


【解决方案1】:

将隐藏字段转换为 base 64 字符串

 @Html.HiddenFor(model => Convert.ToBase64String(Encoding.UTF8.GetBytes(model.agent)));

你可以为它创建扩展方法并做喜欢

@Html.HiddenFor(model => model.agent.ToBase64())

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-19
    • 2011-10-18
    • 2011-09-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多