Infinite Menus, Copyright 2006, OpenCube Inc. All Rights Reserved.  
Support Centre -

- ASP.NET application determine whether cookies are enabled
- application to display non-English language
- Connect application to MySQL
- Invalid Viewstate on ASP.NET pages
- Sending emails in ASP.NET 2.0
- Sending mail from ASP.NET
ASP.NET application determine whether cookies are enabled

Determining whether cookies are enabled requires a round trip to the browser. The basic strategy is to return a cookie in an HTTP response and redirect to a page that checks for the cookie.

Here's a the scenario:

<form runat="server">
<asp:Button Text="Cookie Support" OnClick="OnTest" RunAt="server">

<script language="C#" runat="server">
void OnTest (Object sender, EventArgs e)
HttpCookie cookie = new HttpCookie ("UserIdentifier", "Bob");
Response.Cookies.Add (cookie);
Response.Redirect ("OtherPage.aspx");

And here's the page that it redirects to (OtherPage.aspx). This page uses the presence or absence of the cookie to determine whether cookies are enabled and displays the result:

<%@ Page Language="C#" %>

HttpCookie cookie = Request.Cookies["UserIdentifier"];
if (cookie != null && cookie.Value == "Bob")
Response.Write ("Cookies are enabled");
Response.Write ("Cookies are not enabled");
</html> application to display non-English language allows the developer to encode the page using character sets other than unicode. If your page containing foreign characters does not render properly when served from our webservers, you may need to change the FileEncoding setting in the web.config file.

fileEncoding="<code page>"
requestEncoding="<code page>"
responseEncoding="<code page>"

For more information on code page, please review these articles:
Connect application to MySQL

Methods can be used to connect an application to MySQL database.

1. Using a ODBC .net data provider
2. Using a MySQL Data Provider

1. ODBC version

using System.Data.Odbc;


string connString = "DRIVER={MySQL ODBC 3.51 Driver};; user=dbUsername;password=dbPassword;database=dbName;";

OdbcConnection odbcConn = new OdbcConnection(connString);

2. MySql Data Provider

You will need to import the MySql.Data assembly into your project.
You can get it here:

It is used like this:
using MySql.Data.MySqlClient;


string connString = "Data;Database=dnName;User

MySqlConnection objConnection = new MySqlConnection(connString);

Invalid Viewstate on ASP.NET pages

You may receive the following error message from ASP.NET pages.

[HttpException (0x80004005): Authentication of viewstate failed. 1) If this is a cluster, edit configuration so all servers use the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster. 2) Viewstate can only be posted back to the same page. 3) The viewstate for this page might be corrupted.]

Viewstate represents the state of the page when it was last processed on the server. The contents of the page are stored in a container and moved to and from the server on each request. By default, ASP.NET validates the contents of viewstate to ensure that it has not been tampered. If this validation test fails, an invalid viewstate exception is thrown. One of the issues that cause this test to fail is the recycling of the AppPool where the website lives.

IIS 6 will periodically recycle the application pool to maintain the health of the application pool. At the instance when the application pool is being recycled, browser requests may sometimes result in an invalid viewstate error.

The workaround is to use a specific key in the Web.config to prevent automatic key generation on each process start. The key must be exactly 128 bits made up of random characters and inserted into the configuration file on each webserver experiencing the problem. An example follows.
<<machineKey validationKey=
"EE94EFA0280BBF3A1FE0E8DC5FE9EB725C3CE9D0E59187EC91CF32B463241B4E D6A60E3152B158D30B5BD45D99F09D504D3F75AE860605A11806EDBEF88DAB3F"
"24996804B8C6C416BF7AE6BE7337AE590E404C00A91DB274" validation="SHA1">

You can generate a pair of keys at the following page:
Sending emails in ASP.NET 2.0

// using System.Net.Mail;
// using System.Net;

SmtpClient smtpClient = new SmtpClient("");

smtpClient.Credentials = new NetworkCredential("", "passwordHere");

MailMessage message = new MailMessage();

message.From = new MailAddress(;
message.To.Add(new MailAddress(;
message.To.Add(new MailAddress(;

message.Subject = "This is my subject";
message.Body = "This is the content";


Sending mail from ASP.NET

// using System.Web.Mail - this example is for ASP.NET 1.1;

MailMessage eMail = new MailMessage();

eMail.Fields[""] = 1;
eMail.Fields[""] = "";
eMail.Fields[""] = "password";

eMail.To = ""; // Recipients
eMail.From = "";
eMail.Subject = "This is the subject line";
eMail.Body = "Test Message";

SmtpMail.SmtpServer = "";

To test, just change with the domain name and use one existent email account to authenticate in the smtp server.
To create an email account, log in the hosting manager.

These examples may not work for you without certain modifications.
The purpose of the examples is to give you a general idea on the topic.

  Support Centre - FAQ
Coding Components
Scripting Support

Demo LiveStats
Demo WebMail
Demo Hosting Manager
Disclaimer Privacy Policy Service Guarantee Terms & Conditions

807-966 Inverhouse Dr., Mississauga-ON, L5J4B6 -
Phone: 905-919-9949 - Fax: 905-823-5895 - Toll-Free: 1-866-818-3162
© 2004-2014 TJ-Hosting - All Rights Reserved.