假設我希望使用antiXSS將我的項目的用戶控件中的<input>
標記編碼爲XSS。無法從'System.Web.UI.HtmlControls.HtmlInputText'轉換爲'string'與HtmlEncode AntiXSS
searchbox.ascx
<input id="searchBox" type="text" class="QueryBox" runat="server" />
searchbox.ascx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Security.Application;
namespace Project2015.Website.layout.search
{
public partial class searchbox : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
searchBox = Encoder.HtmlEncode(searchBox);
}
}
}
當我嘗試編譯我的代碼,我收到此錯誤
Error 108 Argument 1: cannot convert from 'System.Web.UI.HtmlControls.HtmlInputText' to 'string'
Error 107 The best overloaded method match for 'Microsoft.Security.Application.Encoder.HtmlEncode(string)' has some invalid arguments
不能看到什麼我在這裏做錯了。
我收到以下錯誤:System.Web.UI.HtmlControls.HtmlInputText'不包含「文本」的定義,也沒有接受類型爲「System.Web.UI」的第一個參數的擴展方法「文本」。 HtmlControls.HtmlInputText'可以找到(你是否缺少使用指令或程序集引用? – Phosy
嘗試.Value而不是.Text –
與.Value我得到一個NullReferenceException [NullReferenceException:對象引用未設置爲對象的實例。] C:\ inetpub \ wwwroot \ Project2015 \ Website \ layout \ search \ searchbox.ascx.cs中的Project2015.Website.layout.searchbox.Page_Load(Object sender,EventArgs e):15 System.Web.UI.Control .OnLoad(EventArgs e)+108 System.Web.UI.Control.LoadRecursive()+67 System.Web.UI.Control.LoadRecursive()+164 System.Web.UI.Control.LoadRecursive()+164 System.Web.UI.Page.ProcessRequestMain(布爾includeStagesBeforeAsyncPoint,布爾includeStagesAfterAsyncPoint)4497米 – Phosy