Perbedaan antara <%: … %> dan <%= … %>

Di ASP.Net MVC 1 (.Net 3.5), anda akan menemui tag berikut untuk merender value ke html. Akan tetapi, penggunaan tag tersebut harus disertai dengan Html.Encode untuk mencegah terjadi XSS attack. contoh:

[csharp]<%= Model.SomeProperty %>[/csharp] menjadi [csharp]<%= Html.Encode(Model.SomeProperty) %>[/csharp]

Pada ASP.Net MVC 2 (.Net 4.0) anda cukup melakukan ini

[csharp]<%: Model.SomeProperty %>[/csharp] untuk menghindari XSS attack, karena string didalam tag tersebut akan secara otomatis di encode tanpa harus menspesifikasian encoding dengan Html.Encode.

Be Sociable, Share!

2 Responses to “Perbedaan antara <%: … %> dan <%= … %>”

  1. kunderemp says:

    Whoo… ternyata memang fitur .Net 4.0. Pantas aja waktu project web klien diubah ke .Net 3.5, ngambek.

Leave a Reply

Your email address will not be published. Required fields are marked *

*


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

[+] kaskus emoticons nartzco