voidApplication_Start(object sender, EventArgs e)
{
if (Convert.ToBoolean(Session["AppStartStatus"]) == true)
{
// Code that runs on application startup// Warranty Automation ApplicationSqlConnectionconGlobal=newSqlConnection
(@"Data Source=.\SQLEXPRESS;AttachDbFileName=|DataDirectory|\TRANE.mdf;Integrated Security=True;User Instance=True");
conGlobal.Open();
string selService;
selService = "Select * From ServiceLink WHERE DatetimeSched='" + DateTime.Now.ToShortDateString() + "'";
SqlCommandglobalCom=newSqlCommand(selService, conGlobal);
SqlDataReaderglobalReader= globalCom.ExecuteReader();
if (globalReader.HasRows)
{
while (globalReader.Read())
{
string affectedserials;
affectedserials = globalReader["UnitSerial"].ToString();
//create the mail messageMailMessagemail=newMailMessage();
//set the addresses
mail.From = newMailAddress("[email protected]");
mail.To.Add("[email protected]");
// the password for both email addresses is "new12345@"//set the content
mail.Subject = "Service Notification";
mail.Body = "A Product with Serial#: " + affectedserials.ToString() + " needs a service visit. Please check the Service Link records right away";
//send the messageSmtpClientsmtp=newSmtpClient();
smtp.EnableSsl = true;
smtp.Send(mail);
}
globalReader.Close();
string updateDate;
updateDate = "UPDATE ServiceLink SET DatetimeSched = '" + DateTime.Now.AddMonths(6).ToShortDateString() + "' WHERE DatetimeSched = '" + DateTime.Now.ToShortDateString() + "'";
SqlCommandcomDateupdate=newSqlCommand(updateDate, conGlobal);
comDateupdate.ExecuteNonQuery();
}
}
elseif (Convert.ToBoolean(Session["AppStartStatus"]) == false)
{
//create the mail messageMailMessagemail=newMailMessage();
//set the addresses
mail.From = newMailAddress("[email protected]");
mail.To.Add("[email protected]");
// the password for both email addresses is "new12345@"//set the content
mail.Subject = "Service Notification";
mail.Body = "Service Link is disabled.";
//send the messageSmtpClientsmtp=newSmtpClient();
smtp.EnableSsl = true;
smtp.Send(mail);
}
elseif (Session["AppStartStatus"] == null)
{
//Make AppStart Status By default true
Session["AppStartStatus"] = true;
}
}
its an email service that detects if a product needs a warranty. anyway i also have a separate control page for this with a simple stop/start button.
the appstartstatus idea was given to me by a member of this community but it doesnt seem to work. what am i doing wrong?
the first time i start i get this error message:
Session state is not available in this context.
Session state is not available in this context.
Description:
An unhandled exception occurred during the execution of the current web
request. Please review the stack trace for more information about the error and
where it originated in the code.
Exception Details:
System.Web.HttpException: Session state is not available in this
context.
Source Error:
Code
Line 16:
Line 17:
Line 18: if (Convert.ToBoolean(Session["AppStartStatus"]) == true)
Line 19: {
Line 20:
its appears that i cant fire up the session control?
thanks in advance, and i need the help urgently :(( . . . .
6 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Kirtan PatelRank #292 · 8.6K reputationPosted Dec 12, 2009, 9:55 PM EST
✓ Accepted answer0
Sorry Friend, if Session Does not working there then try ApplicationState to Store the variable
// Code that runs on application start up
Code
Application.Add("AppStartStatus", true);
if (Convert.ToBoolean(Application.Get("AppStartStatus")) == true)
{
// Do somthign Else Do Somthing
}
Kirtan PatelRank #292 · 8.6K reputationPosted Dec 12, 2009, 9:55 PM EST
// Code that runs on application start up
Mark Uy130 reputationPosted Dec 12, 2009, 10:11 PM EST
Mark Uy130 reputationPosted Dec 12, 2009, 10:21 PM EST
using application.get dont work though:
Application.Get["AppStartStatus"] = false;
is an exception.
any additional help?
Kirtan PatelRank #292 · 8.6K reputationPosted Dec 12, 2009, 10:45 PM EST
and You have used Application.Get[] its Aplication.Get("VariableName") // Its round Braces
its typing mistake :)
Happy Coding :)
and Mark my answer "do you like this answer" if it helps you :)
Mark Uy130 reputationPosted Dec 12, 2009, 11:43 PM EST
using round braces would require a variable since it will be modified to a method right?
and regarding the buttons.
or maybe i should use this on the the stop/start buttons?
Application.Add("AppStartStatus", true) for the start button.
Application.Add("AppStartStatus", false) for the stop button.
im not really familiar with the application.add sequence.
Kirtan PatelRank #292 · 8.6K reputationPosted Dec 13, 2009, 12:00 AM EST