对html标签进行解码,以便在返回服务器(更具体地说是控制器)时可以读取它

本文关键字:具体地说 控制器 读取 返回 标签 html 解码 服务器 | 更新日期: 2024-09-19 10:19:18

我的引擎是Aspx。

如何解码/编码文本框中的html标记。我有html标签
,以使它更可读。我尝试了ValidationRequest和htmlDecode(freqQuestion.Answer),但没有成功。我只是不断收到同样的信息。

"/Administrator"应用程序中的服务器错误。

潜在危险的请求。从中检测到窗体值客户(QuestionAnswer="…ics电话:
123-456-7890

描述:请求验证检测到潜在危险客户端输入值,并且请求的处理已中止。此值可能表示有人试图破坏您的应用程序,例如跨站点脚本攻击。允许页面覆盖应用程序请求验证设置,设置httpRuntime配置中的requestValidationMode属性节请求ValidationMode="2.0"。示例:。设置此值后,您可以通过在中设置validateRequest="false"来禁用请求验证Page指令或在配置节中。然而强烈建议您的应用程序明确检查所有输入在这种情况下。有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkId=153133.

View Page
  <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" validateRequest="false" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    EditFreqQuestionsUser
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script type="text/javascript">
    $(document).ready(function () {
        $("#freqQuestionsUserUpdateButton").click(function () {
            $("#updateFreqQuestionsUser").submit();
        });
    });
</script>
<h2>Edit Freq Questions User </h2>
<%Administrator.DarkstarAdminProductionServices.FreqQuestionsUser freqQuestionsUser = ViewBag.freqQuestionsUser != null ? ViewBag.freqQuestionsUser : new Administrator.DarkstarAdminProductionServices.FreqQuestionsUser(); %>
<%List<string> UserRoleList = Session["UserRoles"] != null ? (List<string>)Session["UserRoles"] : new List<string>(); %>
<form id="updateFreqQuestionsUser" action="<%=Url.Action("SaveFreqQuestionsUser","Prod")%>" method="post">
    <table> 
        <tr>
            <td colspan="3" class="tableHeader">Freq Questions User Details <input type ="hidden" value="<%=freqQuestionsUser.freqQuestionsUserId%>" name="freqQuestionsUserId"/> </td>
        </tr>
         <tr>
            <td colspan="2" class="label">Question Description:</td>
            <td class="content">
                <input type="text" maxlength="2000" name="QuestionDescription" value="<%=freqQuestionsUser.questionDescription%>" />
            </td>
        </tr>
         <tr>
            <td colspan="2" class="label">QuestionAnswer:</td>
            <td class="content">
                <input type="text" maxlength="2000" name="QuestionAnswer" value="<%=Server.HtmlDecode(freqQuestionsUser.questionAnswer)%>" />
            </td>
        </tr>
        <tr>
            <td colspan="3" class="tableFooter">
                    <br />
                    <a id="freqQuestionsUserUpdateButton" href="#" class="regularButton">Save</a>
                    <a href="javascript:history.back()" class="regularButton">Cancel</a>
            </td> 
        </tr>
    </table>
</form>
</asp:Content>

控制器

  [AuthorizeAttribute(AdminRoles = "EditFreqQuestionsUser")]
    public ActionResult SaveFreqQuestionsUser(string QuestionDescription, string QuestionAnswer)
    {
        Guid freqQuestionsUserId = Request.Form["freqQuestionsUserId"] != null ? new Guid(Request.Form["freqQuestionsUserId"]) : Guid.Empty;

        //load agreement eula ref
        AdminProductionServices.FreqQuestionsUser freqqQuestionsUser = Administrator.Models.AdminProduction.FreqQuestionsUser.LoadFreqQuestionsUser(freqQuestionsUserId, string.Empty, string.Empty)[0];
        freqqQuestionsUser.questionDescription = QuestionDescription;
        freqqQuestionsUser.questionAnswer = QuestionAnswer;
        //save it
               Administrator.Models.AdminProduction.FreqQuestionsUser.addFreqQuestionsUser(freqqQuestionsUser);
        return RedirectToAction("SearchFreqQuestionsUser", "Prod", new { FreqQuestionsUserId = freqQuestionsUserId });
    }

对html标签进行解码,以便在返回服务器(更具体地说是控制器)时可以读取它

ValidateRequest指令不适用于MVC,因为与WinForms不同,.aspx文件不是接收请求的实体。控制器是。因此,控制器是您应该禁用验证的位置。只需将[ValidateInput(false)]属性应用于您的操作或整个控制器,运行时就会传递您的标记。