Showing posts with label course. Show all posts
Showing posts with label course. Show all posts

Thursday, March 29, 2012

Server side tag syntax?

I'm using a sample of course code that has server-side tags in different syntaxes, and I don't understand the difference between them:

<%$ ConnectionString:bnDefaultCS%>

<%# Country%>

I can't find a help file or web page that explains the difference (probably because search engines ignore those characters).

What does the $ mean and what does the # mean? are there any others I'm missing?


<%# Country%> // DataBinding (binds the property value)

Country is a public property of the page probably... something like Public String Coutry... in the codebehind.

<%$ ConnectionString:bnDefaultCS%> // If i am not mistaken this is called 'expressions' Where ConnectionString is the expresion and bnDefautlCS is the param it expects, kind of. so for example with resources.. it looks like<%$Resources:Class,ResourceID%>

Is declaritve syntax for special elements that can be created in the frameowrk.

So for example <%$ ConnectionString: is telling the frameowrk to look in web.config and find the connectionString "bnDefaultCS" ( the same type of stuff is used for resource files. )

There is proably a much nicer, more technical answer someone will probaly add to this thread, but as far as functionality that is the basics.

Thursday, March 22, 2012

Server.HTMLEncode/Decode and Databinding

I am using Server.HTMLEncode on user input prior to storing it in an sql table, and of course I use Server.HTMLDecode before displaying it or presenting the data back to the user for editing. HOWEVER, when I bind the data to a dropdownlist or similar control it is not "HTML decoded" and chars like & amp ; appear. My question is: is there anyway around this other then using a for next loop (and decoding selected fields) to get the data into the dropdown list. ThanksMy question would be why would you html encode before sending to the database and decode before sending to the client?
bleroy, maybe this is his reason:

Use Server.HTMLEncode for strings stored in a database

If your ASP pages display strings stored in database fields, you should always process the strings with the Server.HTMLEncode method, otherwise the string won't be displayed correctly in the user's browser if it contains characters that have a special meaning to HTML, such as the quote ("), the less-than (<) and greater-than (>) symbols, the ampersand symbol (&), and any character whose ANSI code is larger than 127.
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q253119

recommends using Server.HTMLEncode from forms and querystrings:

HOWTO: Review ASP Code for CSSI Vulnerability

This article describes how to identify and correct Active Server Pages (ASP) applications that are susceptible to Cross-Site Scripting Security Issues (CSSI). Only input that is not correctly validated or formatted makes your application vulnerable to attack.
You both are beside the point here.

Encoding before sending TO the database and decoding what comes FROM the database is absolutely useless. The database won't suffer from any javascript injections, believe me. Sql injections, perhaps, but X-site scripting, no way.

These papers explain how you should encode any data FROM THE USER TO THE PAGE.

So if you're storing user data to the database, you may encode it at this point or when fetching it back from the database, but don't DECODE what comes from the database before sending it to the client.

It's the "and of course [?] I use Server.HTMLDecode before displaying it or presenting the data back to the user for editing" from the original post that is utterly wrong.
> Encoding before sending TO the database and decoding what comes FROM the database is absolutely useless.

> These papers explain how you should encode any data FROM THE USER TO THE PAGE.

What is stored in the database (from the user) will be displayed on the page. Is is still wrong?