簡體   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