Session Based Server Management (ASP.NET PROGRAM)

         Session contains a sequence of requests for various functions in different states. Requests in different states have different opportunities to turn themselves to be profitable. A scalable server should also provide different levels of Quality of service to requests in different states in each session so that profitable requests like order and checkout can be completed in a timely manner.
main.aspx
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace _2DSession
{
     
      public partial class home1 : System.Web.UI.Page
      {
     
            protected void Page_Load(object sender, System.EventArgs e)
            {
                  codings cl=new codings();
                  DataSet dt=cl.sessioncheck(Session["aa"].ToString());
                  int sum;
                  sum=0;
                  for(int i=0;i<dt.Tables[0].Rows.Count;i++)
                  {                            
                        sum=sum + Convert.ToInt32(dt.Tables[0].Rows[i].ItemArray[0].ToString());
                       
                  }
            Session["ss"]=Convert.ToString(sum);
                  int j=Convert.ToInt32(Session["ss"].ToString());
                  if(j<2000)
                  {
                        if(Page.IsPostBack==false)
                        {
                              DateTime time=(DateTime)Session["starttime"];
                              TimeSpan ts=DateTime.Now.Subtract(time);
                              if(ts.TotalSeconds>30)
                              {
                                    Session.Abandon();
                                    Response.Redirect("home.aspx");
                              }
                        }
                  }
                  else if(j>2000)
                  {
                        if(Page.IsPostBack==false)
                        {
                              DateTime time=(DateTime)Session["starttime"];
                              TimeSpan ts=DateTime.Now.Subtract(time);
                              if(ts.TotalSeconds>60)
                              {
                                    Session.Abandon();
                                    Response.Redirect("home.aspx");
                              }
                        }
                  }
                  else if(j>5000)
                  {
                        if(Page.IsPostBack==false)
                        {
                              DateTime time=(DateTime)Session["starttime"];
                              TimeSpan ts=DateTime.Now.Subtract(time);
                              if(ts.TotalSeconds>300)
                              {
                                    Session.Abandon();
                                    Response.Redirect("home.aspx");
                              }
                        }
                  }
                  if(Session["aa"].ToString()=="")
                  {
                        Response.Redirect("logout.aspx");
                  }
            }
            #region Web Form Designer generated code
            override protected void OnInit(EventArgs e)
            {
                 
                  InitializeComponent();
                  base.OnInit(e);
            }
           
            private void InitializeComponent()
            {   
            }
            #endregion
            protected void LinkButton1_Click(object sender, System.EventArgs e)
            {
                  Session["aa"]="";
                  Response.Redirect("logout.aspx");
            }
      }
}
home.aspx
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace _Session
{
      public partial class bdetails : System.Web.UI.Page
      {
     
            protected void Page_Load(object sender, System.EventArgs e)
            {
                  codings cl=new codings();
                  DataSet dt=cl.sessioncheck(Session["aa"].ToString());
                  int sum;
                  sum=0;
                  for(int i=0;i<dt.Tables[0].Rows.Count;i++)



                  {                            
                        sum=sum + Convert.ToInt32(dt.Tables[0].Rows[i].ItemArray[0].ToString());
                       
                  }
                  Session["ss"]=Convert.ToString(sum);
                  int j=Convert.ToInt32(Session["ss"].ToString());
                  if(j<2000)
                  {
                        if(Page.IsPostBack==false)
                        {
                              DateTime time=(DateTime)Session["starttime"];
                              TimeSpan ts=DateTime.Now.Subtract(time);
                              if(ts.TotalSeconds>30)
                              {
                                    Session.Abandon();
                                    Response.Redirect("home.aspx");
                              }
                        }
                  }
                  else if(j>2000)
                  {
                        if(Page.IsPostBack==false)
                        {
                              DateTime time=(DateTime)Session["starttime"];
                              TimeSpan ts=DateTime.Now.Subtract(time);
                              if(ts.TotalSeconds>60)
                              {
                                    Session.Abandon();
                                    Response.Redirect("home.aspx");
                              }
                        }
                  }
                  else if(j>5000)
                  {
                        if(Page.IsPostBack==false)
                        {
                              DateTime time=(DateTime)Session["starttime"];
                              TimeSpan ts=DateTime.Now.Subtract(time);
                              if(ts.TotalSeconds>300)
                              {
                                    Session.Abandon();
                                    Response.Redirect("home.aspx");
                              }
                        }
                  }
                  if(Session["aa"].ToString()=="")
                  {
                        Response.Redirect("logout.aspx");
                  }
                  codings cl1=new codings();
                  DataSet dt1=cl1.branch1();
                  int a=dt1.Tables[0].Rows.Count ;
                  DropDownList1.Items.Add("---select---");
                  for(int i=0;i<a;i++)
                  {
                        DropDownList1.Items.Add(dt1.Tables[0].Rows[i].ItemArray[0].ToString());
                  }
                                   
            }
            #region Web Form Designer generated code
            override protected void OnInit(EventArgs e)
            {
                 
                  InitializeComponent();
                  base.OnInit(e);
            }
           
           
            private void InitializeComponent()
            {   
            }
            #endregion
            protected void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
            {
                  codings cs=new codings();
                  DataSet dt1=cs.branch12(DropDownList1.SelectedItem.Text);
                  txtbname.Text=dt1.Tables[0].Rows[0].ItemArray[1].ToString();
                  txtplace.Text=dt1.Tables[0].Rows[0].ItemArray[2].ToString();
                  txtaddress.Text=dt1.Tables[0].Rows[0].ItemArray[3].ToString();
                  txtpnumber.Text=dt1.Tables[0].Rows[0].ItemArray[4].ToString();
                  txtmail.Text=dt1.Tables[0].Rows[0].ItemArray[5].ToString();
            }
            protected void LinkButton1_Click(object sender, System.EventArgs e)
            {
                  Session["aa"]="";
                  Response.Redirect("logout.aspx");
            }
      }
}
OUTPUT 


Share:

Send Email via SMTP (ASP.NET PROGRAM)



The SMTP email portion application will demonstrate the following:
  • Using SMTP to configure and send email messages
  • Adding ‘CC’ addresses as message recipients
  • Adding attachments to a message
Imports System
Imports System.Net
Imports System.Net.Mail
Partial Class Default2
    Inherits System.Web.UI.Page
    Private mMailServer As String
    Private mTo As String
    Private mFrom As String
    Private mMsg As String
    Private mSubject As String
    Private mPort As Integer  
 Protected Sub btnSend_Click(ByVal sender As Object, _
              ByVal e As System.EventArgs) Handles btnSend.Click
       Dim strMsg As String
        strMsg = txtMessage.Text
        mTo = Trim(txtTo.Text)
        mFrom = Trim(txtFrom.Text)
        mSubject = Trim(txtSubject.Text)
        mMsg = Trim(txtMessage.Text)
        mMailServer = ConfigurationManager.AppSettings.Get("MyMailServer")
        mPort = ConfigurationManager.AppSettings.Get("MyMailServerPort")
        mCC = Trim(txtCC.Text)
        Try
            Dim message As New MailMessage(mFrom, mTo, mSubject, mMsg)
            If fileAttachments.HasFile Then
            Dim attached As New
              Attachment(Trim(fileAttachments.PostedFile.FileName.ToString()))
                message.Attachments.Add(attached)
            End If
            If mCC <> "" Or mCC <> String.Empty Then
                Dim strCC() As String = Split(mCC, ";")
                Dim strThisCC As String
                For Each strThisCC In strCC
                    message.CC.Add(Trim(strThisCC))
                Next
            End If
            Dim mySmtpClient As New SmtpClient(mMailServer, mPort)
            mySmtpClient.UseDefaultCredentials = True
            mySmtpClient.Send(message)
            MessageBox("The mail message has been sent to " & message.To.ToString())
        Catch ex As FormatException
            MessageBox("Format Exception: " & ex.Message)
        Catch ex As SmtpException
            MessageBox("SMTP Exception:  " & ex.Message)
        Catch ex As Exception
            MessageBox("General Exception:  " & ex.Message)
        End Try
    End Sub
  Protected Sub Button2_Click(ByVal sender As Object, _
          ByVal e As System.EventArgs) Handles Button2.Click
        Dim strMsg As String
        strMsg = txtMessage.Text
        If strMsg.Length >= 140 Then
            strMsg = strMsg.Substring(1, 140)
        End If
        mTo = Trim(txtToNumber.Text) & _
              Trim(cboCarrier.SelectedItem.ToString())
        mFrom = Trim(txtFrom.Text)
        mSubject = Trim(txtSubject.Text)
        mMsg = Trim(txtMessage.Text)
        mMailServer = ConfigurationManager.AppSettings.Get("MyMailServer")
        mPort = ConfigurationManager.AppSettings.Get("MyMailServerPort")
        Try
            Dim message As New MailMessage(mFrom, mTo, mSubject, mmsg)
            Dim mySmtpClient As New SmtpClient(mMailServer, mPort)
            mySmtpClient.UseDefaultCredentials = True
            mySmtpClient.Send(message)
            MessageBox("The mail message has been sent to " & _
                        message.To.ToString())
        Catch ex As FormatException
            MessageBox("Format Exception: " & ex.Message)
        Catch ex As SmtpException
            MessageBox("SMTP Exception:  " & ex.Message)
        Catch ex As Exception
            MessageBox("General Exception:  " & ex.Message)
        End Try
    End Sub
End Class

OUTPUT 
 
Share:

Selective Validation (ASP.NET PROGRAM)

This enhancement allows specifying selective partial validation in a web form using validation controls. Each validation group is evaluated separately from other validation groups in the web form. You can specify Validation Groups by setting the Validation Group Property of Validation Controls to a value. All the Validation Controls with the same value set for the Validation Group property are included in the same Validation Group.
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<center><H3> Validation Groups Sample</H3>
<div style="width:60%;border-bottom:blue thin solid;border-top:blue thin solid;border-left:blue thin solid;border-right:blue thin solid">
&nbsp;<br />
<center>
<table border="0">
<tr>
<td style="width: 100px; height: 23px">
User ID</td>
<td style="width: 215px; height: 23px">
<asp:TextBox ID="txtLogin" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtLogin"
ErrorMessage="User ID is required" ValidationGroup="VGrpAuthenticate">*</asp:RequiredFieldValidator></td>
</tr>
<tr>
<td style="width: 100px; height: 23px">
Password</td>
<td style="width: 215px; height: 23px">
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtPassword"
ErrorMessage="Password cannot be blank" ValidationGroup="VGrpAuthenticate">*</asp:RequiredFieldValidator></td>
</tr>
<tr>
<td style="width: 100px; height: 21px">
NickName</td>
<td style="width: 215px; height: 21px">
<asp:TextBox ID="txtNickName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 

ControlToValidate="txtNickName"
ErrorMessage="NickName is required" ValidationGroup="VGrpAnon">*</asp:RequiredFieldValidator></td>
</tr>
<tr>
<td style="height: 21px" colspan="2">
<br />
<asp:Button ID="btnLoginAuth" runat="server" Text="Login" ValidationGroup="VGrpAuthenticate" />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
<asp:LinkButton ID="LinkButton1" runat="server" ValidationGroup="VGrpAnon">Login as Guest</asp:LinkButton><br />
</td>
</tr>
</table>
</center>
</div>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="True"
ShowSummary="False" ValidationGroup="VGrpAuthenticate" />
<asp:ValidationSummary ID="ValidationSummary2" runat="server" ValidationGroup="VGrpAnon" />
</center>
</form>
</body>
</html>

OUTPUT
 
Share:

Total Pageviews

CONTACT US

Prof. Roshan P. Helonde
Mobile: +917276355704
WhatsApp: +917276355704
Email: roshanphelonde@rediffmail.com

Enter Project Title

Popular Projects

All Archive

Contact Form

Name

Email *

Message *