Session Management (AWT)
Session Management (AWT)
namespace Assignment4
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Code :-
WebForm2.aspx
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<div>
</div>
<br />
<asp:Button ID="Button1" runat="server" Text="Show"
OnClick="Button1_Click" PostBackUrl="~/WebForm3.aspx" />
</form>
</body>
</html>
WebForm3.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Assignment4
Response.Write(Request.Form["HiddenField1"].ToString());
}
3. Write a program to demonstrate the Query String.
WebForm1.aspx
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<div>
</div>
</div>
</form>
</body>
</html>
WebForm1.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication6
Response.Redirect("WebForm2.aspx?msg=" + TextBox1.Text);
WebForm2.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication6
if (Request.QueryString["msg"] != null)
Response.Write(Request.QueryString["msg"].ToString());
else
Response.Redirect("WebForm1.aspx");
}
Output :-
4. Create a web application to get following information from a user. Name, Age,
height, Email, Gender. Validate the input by using proper validation control. If the
gender is male then navigate to Male.aspx web page, and if the gender is female then
navigate to Female.aspx. Then depending upon the gender and height of the
individual suggest the ideal weight.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication7
cookie.Values["Age"] = TextBox2.Text;
cookie.Values["Height"] = TextBox3.Text;
cookie.Values["Email"] = TextBox4.Text;
cookie.Values["gender"] = gender;
Response.Cookies.Add(cookie);
if (gender == "Male")
Response.Redirect("~/male.aspx");
else
Response.Redirect("~/Female.aspx");
male.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication7
int weight = 0;
Response.Write("Name: " + name + " \n Age: " + age + "\n Height:" + height + "\n
Email: " + email + "\n Ideal Weight: " + weight);
Female.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication7
{
int weight = 0;
Response.Write("Name: " + name + " \n Age: " + age + "\n Height:" + height + "\n
Email: " + email + "\n Ideal Weight: " + weight);
5. Create an ASP.NET web application for your college fest. Provide login function
and registration for a few events. Use cookies to maintain the user's session.
WebForm.aspx
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Net.NetworkInformation;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication8
con.Open();
if (result > 0)
Response.Redirect("~/WebForm2.aspx");
else
con.Close();
TextBox1.Text = String.Empty;
TextBox2.Text = String.Empty;
TextBox3.Text = String.Empty;
TextBox4.Text = String.Empty;
5_Session.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication8
if (Session["user"]!= null)
else
Response.Redirect("~/WebForm2.aspx");
{
}
Session.Abandon();
Session.Remove("user");
Response.Redirect("~/WebForm2.aspx");
WebForm2.aspx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
namespace WebApplication8
conn.Open();
adapter.Fill(dataTable);
if (dataTable.Rows.Count > 0)
{
Session["user"] = TextBox1.Text;
Response.Redirect("~/5_Session.aspx");
}
6. Write a program to count the number of live users in your web application.
WebForm1.aspx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Program_6
Global.asax.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
namespace Program_6
Application["sessioncount"] = 0;
Application.Lock();
Application.UnLock();
Application.Lock();
Application["sessioncount"] = count - 1;
Application.UnLock();
}
}
7. Write a web application to demonstrate page output caching.
WebForm1.aspx
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<div>
<h1>Output Caching</h1>
<%=DateTime.Now.ToString() %>
</div>
</form>
</body>
</html>
WebForm.1aspx
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<div>
</div>
</asp:ScriptManager>
<ContentTemplate>
</asp:Timer>
</ContentTemplate>
<Triggers>
</Triggers>
</asp:UpdatePanel>
</form>
</body>
</html>
WebForm1.aspx.cs
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication10
Label1.Text = DateTime.Now.ToString();
}
9. Write a web application to create an image slider using ajax.
1.