locked
'string' does not contain a definition for 'AssafeHtml' RRS feed

  • Question

  • User311495996 posted

    I followed this tutorial:http://www.mikesdotnetting.com/article/159/webmatrix-protecting-your-web-pages-site

    created a new folder named "App_Code"

    and created a new file named "HtmlSanitizer.cs", placed some c# code in it, including public of AssafeHtml

    after that I created a new file to display a column in the database, codes like below:

    @{   
        var db=Database.Open("database name");
        var sql= db.QuerySingle("SELECT *  from test order by id desc");
        var qq= sql.columnname;
        var qqq= new HtmlString(qqq.ToString().AssafeHtml());
    }
    
    <h1>@qqq</h1>

    When I run it in browser, the yellow screen of death is appeared.

    It mention me:

    'string' does not contain a definition for 'AssafeHtml'

    How can I do?

    thanks for your help!

    Sunday, November 15, 2015 9:11 PM

Answers

  • User-821857111 posted
    string qqq = new HtmlString(qq.AssafeHtml());

    Or

    var qqq = new HtmlString(((string)qq).AssafeHtml());
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 16, 2015 2:21 AM

All replies

  • User-821857111 posted
    string qqq = new HtmlString(qq.AssafeHtml());

    Or

    var qqq = new HtmlString(((string)qq).AssafeHtml());
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 16, 2015 2:21 AM
  • User311495996 posted

    Thank you Mike!

    The second expression did work!

    Monday, November 16, 2015 5:39 AM