简体   繁体   English

Umbraco和ASP.NET请求验证

[英]Umbraco & ASP.NET Request validation

I have a problem with my Umbraco ( v4.7.2 ). 我的Umbraco( v4.7.2 )有问题。

Currently I can't publish content from Umbraco interface because of ASP.NET request validation. 由于ASP.NET请求验证,目前我无法从Umbraco界面发布内容。 When its turn off everything is working like a charm. 关闭时,所有功能都像魅力一样运转。

I was looking for some kind of solution for this because I worry about disabling request validation for my application. 我正在寻找某种解决方案,因为我担心禁用我的应用程序的请求验证。 So I decided to turn off the validation programmatically for some time while it's needed. 因此,我决定在需要时以编程方式关闭验证一段时间。

My first solution was to subscribe to umbraco.cms.businesslogic.web.Document events. 我的第一个解决方案是订阅umbraco.cms.businesslogic.web.Document事件。 For example I can disable validation on Document.BeforePublish event and then turn on validation on Document.AfterPublish event. 例如,我可以禁用对Document.BeforePublish事件的验证,然后打开对Document.AfterPublish事件的验证。 Example: 例:

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
}

But this didn't work because request validation provides validation before Document.BeforePublish event took place. 但这不起作用,因为请求验证在Document.BeforePublish事件发生之前提供了验证。

The second solution was to implement custom UsersMembershipProvider and turning off validation after user has successfully pass authentication. 第二种解决方案是实现自定义的UsersMembershipProvider,并在用户成功通过身份验证后关闭验证。 But the problem is - I can't catch any appropriate event to turn on validation when user for example signs out from Umbraco. 但是问题是-例如当用户从Umbraco注销时,我无法捕获任何适当的事件来打开验证。

Example: 例:

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;
    }
}

Can you please advise something on this? 您能对此提出建议吗? What is best practice to make request validation work with Umbraco? 使Umbraco进行请求验证的最佳实践是什么?

You may need to set the correct version of the .NET request validation. 您可能需要设置正确版本的.NET请求验证。 Umbraco works with version 2.0: Umbraco适用于2.0版:

<httpRuntime requestValidationMode="2.0">

I guess I solve my problem by adding directive EnableEventValidation="false" to Umbraco/editContent.aspx page. 我想我通过将指令EnableEventValidation =“ false”添加Umbraco / editContent.aspx页面来解决我的问题。 By default it also has ValidateRequest="false" . 默认情况下,它也具有ValidateRequest =“ false”

So the thing I was worry about – disabling request validation on application level seems to be not try. 因此,我担心的事情–在应用程序级别禁用请求验证似乎不是尝试。

Having the requestValidationMode=2.0 will only restrict validation for .aspx pages but wont disable it at all. 具有requestValidationMode = 2.0只会限制对.aspx页的验证,而根本不会禁用它。 Also it making possible usage of page directives. 它还使页面指令的使用成为可能。

We can encode the html string data using jQuery before passing to codebehind(asp.net C#) For example - 我们可以在传递给codebehind(asp.net C#)之前使用jQuery对html字符串数据进行编码,例如-

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

and the output will look like - 和输出看起来像-

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

Then Decode data to show HTML(without HTML tag show) - 然后解码数据以显示HTML(不显示HTML标签)-

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

output will look like - 输出看起来像-

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

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

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