繁体   English   中英

Umbraco和ASP.NET请求验证

[英]Umbraco & ASP.NET Request validation

我的Umbraco( v4.7.2 )有问题。

由于ASP.NET请求验证,目前我无法从Umbraco界面发布内容。 关闭时,所有功能都像魅力一样运转。

我正在寻找某种解决方案,因为我担心禁用我的应用程序的请求验证。 因此,我决定在需要时以编程方式关闭验证一段时间。

我的第一个解决方案是订阅umbraco.cms.businesslogic.web.Document事件。 例如,我可以禁用对Document.BeforePublish事件的验证,然后打开对Document.AfterPublish事件的验证。 例:

public UmbracoPublishHandler()
{
  Document.BeforePublish += Document_BeforePublish;
  Document.AfterPublish += Document_AfterPublish;
}

private void Document_BeforePublish(Document sender, PublishEventArgs args)
{
  //Turn off validation here
}

private void Document_AfterPublish(Document sender, PublishEventArgs args)
{
  //Turn on validation here
}

但这不起作用,因为请求验证在Document.BeforePublish事件发生之前提供了验证。

第二种解决方案是实现自定义的UsersMembershipProvider,并在用户成功通过身份验证后关闭验证。 但是问题是-例如当用户从Umbraco注销时,我无法捕获任何适当的事件来打开验证。

例:

public class CustomUsersMembershipProvider : umbraco.providers.UsersMembershipProvider
{
    public override bool ValidateUser(string username, string password)
    {
        var success = base.ValidateUser(username, password);

        if (success)
        {
           //Turn off validation here 
        }

        return success;
    }
}

您能对此提出建议吗? 使Umbraco进行请求验证的最佳实践是什么?

您可能需要设置正确版本的.NET请求验证。 Umbraco适用于2.0版:

<httpRuntime requestValidationMode="2.0">

我想我通过将指令EnableEventValidation =“ false”添加Umbraco / editContent.aspx页面来解决我的问题。 默认情况下,它也具有ValidateRequest =“ false”

因此,我担心的事情–在应用程序级别禁用请求验证似乎不是尝试。

具有requestValidationMode = 2.0只会限制对.aspx页的验证,而根本不会禁用它。 它还使页面指令的使用成为可能。

我们可以在传递给codebehind(asp.net C#)之前使用jQuery对html字符串数据进行编码,例如-

jQuery('<div />').text('Some text with <div>html</div>').html()

和输出看起来像-

"Some text with &lt;div&gt;html&lt;/div&gt;"

然后解码数据以显示HTML(不显示HTML标签)-

jQuery('<div />').html('Some text with &lt;div&gt;html&lt;/div&gt;').text()

输出看起来像-

"Some text with <div>html</div>"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM