Showing posts with label htmldecode. Show all posts
Showing posts with label htmldecode. Show all posts

Thursday, March 22, 2012

Server.HtmlDecode for windows services (Urgent)

Hello,
does anybody knows the equilant of Server.HtmlDecode when
creating a windows service?
Thanks, SonuI think System.Web.HttpUtility.HtmlDecode, which is a static function,
should do the trick. HttpUtility is a pretty useful class for programs
which don't have access to a Server object like you do in ASP.Net
Karl
MY ASP.Net tutorials
http://www.openmymind.net/
"Sonu Kapoor" <sonukapoor@.gmail.com> wrote in message
news:18a401c4bc81$7f99de90$a601280a@.phx.gbl...
> Hello,
> does anybody knows the equilant of Server.HtmlDecode when
> creating a windows service?
> Thanks, Sonu
Hi Karl,
I get the following error when using this:
"HttpUtility" is not a member of "web".
Sonu

>--Original Message--
>I think System.Web.HttpUtility.HtmlDecode, which is a
static function,
>should do the trick. HttpUtility is a pretty useful
class for programs
>which don't have access to a Server object like you do in
ASP.Net
>Karl
>--
>MY ASP.Net tutorials
>http://www.openmymind.net/
>
>"Sonu Kapoor" <sonukapoor@.gmail.com> wrote in message
>news:18a401c4bc81$7f99de90$a601280a@.phx.gbl...
when
>
>.
>
You don't have the System.Web.dll referenced in your project.
Unfortunately, System.dll actually has a System.Web namespace in it, which
is why the error is what it is. Simply reference System.Web.dll :)
Karl
MY ASP.Net tutorials
http://www.openmymind.net/
"Sonu Kapoor" <sonukapoor@.gmail.com> wrote in message
news:18ba01c4bc87$fde97980$a601280a@.phx.gbl...
> Hi Karl,
> I get the following error when using this:
> "HttpUtility" is not a member of "web".
> Sonu
>
> static function,
> class for programs
> ASP.Net
> when
Hello,
I imported the System.Web via the project properties
and thought that this should be enough. But it wasnt. I
have reference System.Web and it works now. Many thanks.
Sonu

>--Original Message--
>You don't have the System.Web.dll referenced in your
project.
>Unfortunately, System.dll actually has a System.Web
namespace in it, which
>is why the error is what it is. Simply reference
System.Web.dll :)
>Karl
>--
>MY ASP.Net tutorials
>http://www.openmymind.net/
>
>"Sonu Kapoor" <sonukapoor@.gmail.com> wrote in message
>news:18ba01c4bc87$fde97980$a601280a@.phx.gbl...
in
>
>.
>

Server.HtmlDecode for windows services (Urgent)

Hello,

does anybody knows the equilant of Server.HtmlDecode when
creating a windows service?

Thanks, SonuI think System.Web.HttpUtility.HtmlDecode, which is a static function,
should do the trick. HttpUtility is a pretty useful class for programs
which don't have access to a Server object like you do in ASP.Net

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/

"Sonu Kapoor" <sonukapoor@.gmail.com> wrote in message
news:18a401c4bc81$7f99de90$a601280a@.phx.gbl...
> Hello,
> does anybody knows the equilant of Server.HtmlDecode when
> creating a windows service?
> Thanks, Sonu
Hi Karl,

I get the following error when using this:

"HttpUtility" is not a member of "web".

Sonu

>--Original Message--
>I think System.Web.HttpUtility.HtmlDecode, which is a
static function,
>should do the trick. HttpUtility is a pretty useful
class for programs
>which don't have access to a Server object like you do in
ASP.Net
>Karl
>--
>MY ASP.Net tutorials
>http://www.openmymind.net/
>
>"Sonu Kapoor" <sonukapoor@.gmail.com> wrote in message
>news:18a401c4bc81$7f99de90$a601280a@.phx.gbl...
>> Hello,
>>
>> does anybody knows the equilant of Server.HtmlDecode
when
>> creating a windows service?
>>
>> Thanks, Sonu
>
>.
You don't have the System.Web.dll referenced in your project.

Unfortunately, System.dll actually has a System.Web namespace in it, which
is why the error is what it is. Simply reference System.Web.dll :)

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/

"Sonu Kapoor" <sonukapoor@.gmail.com> wrote in message
news:18ba01c4bc87$fde97980$a601280a@.phx.gbl...
> Hi Karl,
> I get the following error when using this:
> "HttpUtility" is not a member of "web".
> Sonu
>
> >--Original Message--
> >I think System.Web.HttpUtility.HtmlDecode, which is a
> static function,
> >should do the trick. HttpUtility is a pretty useful
> class for programs
> >which don't have access to a Server object like you do in
> ASP.Net
> >Karl
> >--
> >MY ASP.Net tutorials
> >http://www.openmymind.net/
> >"Sonu Kapoor" <sonukapoor@.gmail.com> wrote in message
> >news:18a401c4bc81$7f99de90$a601280a@.phx.gbl...
> >> Hello,
> >>
> >> does anybody knows the equilant of Server.HtmlDecode
> when
> >> creating a windows service?
> >>
> >> Thanks, Sonu
> >.
Hello,

I imported the System.Web via the project properties
and thought that this should be enough. But it wasnt. I
have reference System.Web and it works now. Many thanks.

Sonu

>--Original Message--
>You don't have the System.Web.dll referenced in your
project.
>Unfortunately, System.dll actually has a System.Web
namespace in it, which
>is why the error is what it is. Simply reference
System.Web.dll :)
>Karl
>--
>MY ASP.Net tutorials
>http://www.openmymind.net/
>
>"Sonu Kapoor" <sonukapoor@.gmail.com> wrote in message
>news:18ba01c4bc87$fde97980$a601280a@.phx.gbl...
>> Hi Karl,
>>
>> I get the following error when using this:
>>
>> "HttpUtility" is not a member of "web".
>>
>> Sonu
>>
>>
>> >--Original Message--
>> >I think System.Web.HttpUtility.HtmlDecode, which is a
>> static function,
>> >should do the trick. HttpUtility is a pretty useful
>> class for programs
>> >which don't have access to a Server object like you do
in
>> ASP.Net
>>> >Karl
>>> >--
>> >MY ASP.Net tutorials
>> >http://www.openmymind.net/
>>>> >"Sonu Kapoor" <sonukapoor@.gmail.com> wrote in message
>> >news:18a401c4bc81$7f99de90$a601280a@.phx.gbl...
>> >> Hello,
>> >>
>> >> does anybody knows the equilant of Server.HtmlDecode
>> when
>> >> creating a windows service?
>> >>
>> >> Thanks, Sonu
>>>> >.
>>
>.

Server.HtmlDecode for windows services

Hello,

does anybody knows the equilant of Server.HtmlDecode when creating a windows service?

Thanks, SonuHave you tried setting a reference to System.Web and doing:


string decoded = System.Web.HttpContext.Current.Server.HtmlDecode(encodedString);

When using this I get:

"HttpContext" is not a member of "web".

Sonu
uups...sorry I forgot to add the reference. It works now.

Sonu

Server.HTMLDecode doesn't decode char 345

Hello!
I have a problem decoding the czech character:
r
The HTML code for this character is ř but when running
Server.HTMLdecode on that string it just returns ř instead of the real
char. (It works on a lot of other characters)
I need to decode this string in order to render an image with this character
as a part of a headline.
Can anyone help me with this issue, or is it maybe a bug?
/kindest regards, JonasThis works fine for me:
Response.Write(Server.HtmlDecode("ř"));
My web.config specifies:
<globalization requestEncoding="utf-8" responseEncoding="utf-8" />
maybe yours is using something else?
Karl
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Jonas kermark" <jonas@.wipcore.se> wrote in message
news:uY3DJazlFHA.2080@.TK2MSFTNGP14.phx.gbl...
> Hello!
> I have a problem decoding the czech character:
> r
> The HTML code for this character is ř but when running
> Server.HTMLdecode on that string it just returns ř instead of the
> real char. (It works on a lot of other characters)
> I need to decode this string in order to render an image with this
> character as a part of a headline.
> Can anyone help me with this issue, or is it maybe a bug?
> /kindest regards, Jonas
>
Maybe it is because I'm usning the Server object in a function in a non web
environment - a regular class:
string decodedText = System.Web.HttpContext.Current.Server.HtmlDecode(
text );
where the text property sometimes contains the char ř
Is there some way that I can tell the HtmlDecode which encoding to use?
/Jonas
"Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:%23o0ElR1lFHA.3552@.TK2MSFTNGP10.phx.gbl...
> This works fine for me:
> Response.Write(Server.HtmlDecode("ř"));
> My web.config specifies:
> <globalization requestEncoding="utf-8" responseEncoding="utf-8" />
> maybe yours is using something else?
> Karl
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
> come!)
>
> "Jonas kermark" <jonas@.wipcore.se> wrote in message
> news:uY3DJazlFHA.2080@.TK2MSFTNGP14.phx.gbl...
>
i don't think that's your problem (although within a class, there's no
reason not to use System.Web.HttpUtility.HtmlDecode which decouples your
class from the context (ie, it can be reused outside of the web)).
All HtmlDecode does in the case of a numeric value (such as 345), is:
char c1 = (char) ((ushort) int.Parse("345"));
Response.Write(c1);
Is your page encoding set to utf-8? (if you put tracing on, at the top of
the trace information it says the encoding).l
Karl
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Jonas kermark" <jonas@.wipcore.se> wrote in message
news:OELxjb1lFHA.2904@.TK2MSFTNGP14.phx.gbl...
> Maybe it is because I'm usning the Server object in a function in a non
> web environment - a regular class:
> string decodedText = System.Web.HttpContext.Current.Server.HtmlDecode(
> text );
> where the text property sometimes contains the char ř
> Is there some way that I can tell the HtmlDecode which encoding to use?
> /Jonas
> "Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net>
> wrote in message news:%23o0ElR1lFHA.3552@.TK2MSFTNGP10.phx.gbl...
>
Yes the encoding is set ut utf-8
the strange thing is that the decodedText property still contains the
"ř" string after HtmlDecode
Nevermind, thanks for your explanation of the HtmlDecode, I have now created
a SpecialDecode function instead that works fine
private static string SpecialDecode(string decodedText)
{
string tmpResult = decodedText;
bool found = true;
try
{
while(found)
{
if( tmpResult.IndexOf("&#") > -1 )
{
string chars = tmpResult.Substring( tmpResult.IndexOf("&#")+2, 3);
//decode
char c1 = (char) ((ushort) int.Parse(chars));
tmpResult = tmpResult.Replace("&#" + chars + ";", c1.ToString());
}
else
{
found = false;
}
}
}
catch{}
return tmpResult;
}
"Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:e2uGEB2lFHA.3936@.TK2MSFTNGP10.phx.gbl...
>i don't think that's your problem (although within a class, there's no
>reason not to use System.Web.HttpUtility.HtmlDecode which decouples your
>class from the context (ie, it can be reused outside of the web)).
> All HtmlDecode does in the case of a numeric value (such as 345), is:
> char c1 = (char) ((ushort) int.Parse("345"));
> Response.Write(c1);
> Is your page encoding set to utf-8? (if you put tracing on, at the top of
> the trace information it says the encoding).l
> Karl
>
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/ - New and Improved (yes, the popup is
> annoying)
> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
> come!)
> "Jonas kermark" <jonas@.wipcore.se> wrote in message
> news:OELxjb1lFHA.2904@.TK2MSFTNGP14.phx.gbl...
>
Karl Seguin wrote:

> This works fine for me:
> Response.Write(Server.HtmlDecode("ř"));
> My web.config specifies:
> <globalization requestEncoding="utf-8" responseEncoding="utf-8" />
> maybe yours is using something else?
> Karl
Numeric references are based on Unicode code points, thus
requestEncoding and responseEncoding don't apply.
Cheers,
--
http://www.joergjooss.de
mailto:news-reply@.joergjooss.de

Server.HTMLDecode doesnt decode char 345

Hello!

I have a problem decoding the czech character:
r

The HTML code for this character is ř but when running
Server.HTMLdecode on that string it just returns ř instead of the real
char. (It works on a lot of other characters)
I need to decode this string in order to render an image with this character
as a part of a headline.

Can anyone help me with this issue, or is it maybe a bug?

/kindest regards, JonasThis works fine for me:
Response.Write(Server.HtmlDecode("ř"));

My web.config specifies:
<globalization requestEncoding="utf-8" responseEncoding="utf-8" /
maybe yours is using something else?

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)

"Jonas kermark" <jonas@.wipcore.se> wrote in message
news:uY3DJazlFHA.2080@.TK2MSFTNGP14.phx.gbl...
> Hello!
> I have a problem decoding the czech character:
> r
> The HTML code for this character is ř but when running
> Server.HTMLdecode on that string it just returns ř instead of the
> real char. (It works on a lot of other characters)
> I need to decode this string in order to render an image with this
> character as a part of a headline.
> Can anyone help me with this issue, or is it maybe a bug?
> /kindest regards, Jonas
Maybe it is because I'm usning the Server object in a function in a non web
environment - a regular class:

string decodedText = System.Web.HttpContext.Current.Server.HtmlDecode(
text );

where the text property sometimes contains the char ř

Is there some way that I can tell the HtmlDecode which encoding to use?

/Jonas

"Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:%23o0ElR1lFHA.3552@.TK2MSFTNGP10.phx.gbl...
> This works fine for me:
> Response.Write(Server.HtmlDecode("ř"));
> My web.config specifies:
> <globalization requestEncoding="utf-8" responseEncoding="utf-8" />
> maybe yours is using something else?
> Karl
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
> come!)
>
> "Jonas kermark" <jonas@.wipcore.se> wrote in message
> news:uY3DJazlFHA.2080@.TK2MSFTNGP14.phx.gbl...
>> Hello!
>>
>> I have a problem decoding the czech character:
>> r
>>
>> The HTML code for this character is ř but when running
>> Server.HTMLdecode on that string it just returns ř instead of the
>> real char. (It works on a lot of other characters)
>> I need to decode this string in order to render an image with this
>> character as a part of a headline.
>>
>> Can anyone help me with this issue, or is it maybe a bug?
>>
>> /kindest regards, Jonas
>>
i don't think that's your problem (although within a class, there's no
reason not to use System.Web.HttpUtility.HtmlDecode which decouples your
class from the context (ie, it can be reused outside of the web)).

All HtmlDecode does in the case of a numeric value (such as 345), is:

char c1 = (char) ((ushort) int.Parse("345"));
Response.Write(c1);

Is your page encoding set to utf-8? (if you put tracing on, at the top of
the trace information it says the encoding).l

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Jonas kermark" <jonas@.wipcore.se> wrote in message
news:OELxjb1lFHA.2904@.TK2MSFTNGP14.phx.gbl...
> Maybe it is because I'm usning the Server object in a function in a non
> web environment - a regular class:
> string decodedText = System.Web.HttpContext.Current.Server.HtmlDecode(
> text );
> where the text property sometimes contains the char ř
> Is there some way that I can tell the HtmlDecode which encoding to use?
> /Jonas
> "Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net>
> wrote in message news:%23o0ElR1lFHA.3552@.TK2MSFTNGP10.phx.gbl...
>> This works fine for me:
>> Response.Write(Server.HtmlDecode("ř"));
>>
>> My web.config specifies:
>> <globalization requestEncoding="utf-8" responseEncoding="utf-8" />
>>
>> maybe yours is using something else?
>>
>> Karl
>>
>> --
>> MY ASP.Net tutorials
>> http://www.openmymind.net/ - New and Improved (yes, the popup is
>> annoying)
>> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
>> come!)
>>
>>
>> "Jonas kermark" <jonas@.wipcore.se> wrote in message
>> news:uY3DJazlFHA.2080@.TK2MSFTNGP14.phx.gbl...
>>> Hello!
>>>
>>> I have a problem decoding the czech character:
>>> r
>>>
>>> The HTML code for this character is ř but when running
>>> Server.HTMLdecode on that string it just returns ř instead of the
>>> real char. (It works on a lot of other characters)
>>> I need to decode this string in order to render an image with this
>>> character as a part of a headline.
>>>
>>> Can anyone help me with this issue, or is it maybe a bug?
>>>
>>> /kindest regards, Jonas
>>>
>>
>>
Yes the encoding is set ut utf-8

the strange thing is that the decodedText property still contains the
"ř" string after HtmlDecode

Nevermind, thanks for your explanation of the HtmlDecode, I have now created
a SpecialDecode function instead that works fine

private static string SpecialDecode(string decodedText)
{
string tmpResult = decodedText;
bool found = true;
try
{
while(found)
{
if( tmpResult.IndexOf("&#") > -1 )
{
string chars = tmpResult.Substring( tmpResult.IndexOf("&#")+2, 3);
//decode
char c1 = (char) ((ushort) int.Parse(chars));
tmpResult = tmpResult.Replace("&#" + chars + ";", c1.ToString());
}
else
{
found = false;
}
}
}
catch{}

return tmpResult;
}

"Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:e2uGEB2lFHA.3936@.TK2MSFTNGP10.phx.gbl...
>i don't think that's your problem (although within a class, there's no
>reason not to use System.Web.HttpUtility.HtmlDecode which decouples your
>class from the context (ie, it can be reused outside of the web)).
> All HtmlDecode does in the case of a numeric value (such as 345), is:
> char c1 = (char) ((ushort) int.Parse("345"));
> Response.Write(c1);
> Is your page encoding set to utf-8? (if you put tracing on, at the top of
> the trace information it says the encoding).l
> Karl
>
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/ - New and Improved (yes, the popup is
> annoying)
> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
> come!)
> "Jonas kermark" <jonas@.wipcore.se> wrote in message
> news:OELxjb1lFHA.2904@.TK2MSFTNGP14.phx.gbl...
>> Maybe it is because I'm usning the Server object in a function in a non
>> web environment - a regular class:
>>
>> string decodedText = System.Web.HttpContext.Current.Server.HtmlDecode(
>> text );
>>
>> where the text property sometimes contains the char ř
>>
>> Is there some way that I can tell the HtmlDecode which encoding to use?
>>
>> /Jonas
>>
>> "Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net>
>> wrote in message news:%23o0ElR1lFHA.3552@.TK2MSFTNGP10.phx.gbl...
>>> This works fine for me:
>>> Response.Write(Server.HtmlDecode("ř"));
>>>
>>> My web.config specifies:
>>> <globalization requestEncoding="utf-8" responseEncoding="utf-8" />
>>>
>>> maybe yours is using something else?
>>>
>>> Karl
>>>
>>> --
>>> MY ASP.Net tutorials
>>> http://www.openmymind.net/ - New and Improved (yes, the popup is
>>> annoying)
>>> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
>>> come!)
>>>
>>>
>>> "Jonas kermark" <jonas@.wipcore.se> wrote in message
>>> news:uY3DJazlFHA.2080@.TK2MSFTNGP14.phx.gbl...
>>>> Hello!
>>>>
>>>> I have a problem decoding the czech character:
>>>> r
>>>>
>>>> The HTML code for this character is ř but when running
>>>> Server.HTMLdecode on that string it just returns ř instead of the
>>>> real char. (It works on a lot of other characters)
>>>> I need to decode this string in order to render an image with this
>>>> character as a part of a headline.
>>>>
>>>> Can anyone help me with this issue, or is it maybe a bug?
>>>>
>>>> /kindest regards, Jonas
>>>>
>>>
>>>
>>
>>
Karl Seguin wrote:

> This works fine for me:
> Response.Write(Server.HtmlDecode("ř"));
> My web.config specifies:
> <globalization requestEncoding="utf-8" responseEncoding="utf-8" />
> maybe yours is using something else?
> Karl

Numeric references are based on Unicode code points, thus
requestEncoding and responseEncoding don't apply.

Cheers,
--
http://www.joergjooss.de
mailto:news-reply@.joergjooss.de

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?