ASP Notes
ASP Notes
Net
Right Click -> Properties -> Allow Paging (true) ->Page Size(enter preferred
pages) -> Go to Event -> Page Index Changing (handle this event) ->
Repeater Control
Repeater is a unstructured control. We have design it's column by our requirement.
DataList
This control is used to display back-end data in front-end like GridView.
The Speciality of this control is that it display the data in the form of columns.
It is not able to show data itself if we want to show data we have to design it's column.
20/02/2024 Configuration Support in ASP.Net
Note- In HTML there are predefined tags while in XML we can define our own tags. XML file is not compile direct run
<appsettings>
<add key="ri" value="18.24"/>
</appsettings>
----C# file----
using System.Configuration
Lable1.Text=ConfigurationManager.Appsettings["ri"];
2- <connectionstring> tag - This tag is used to define connection string globaly by which we can call it anywhere in our
project
<connectionstring>
<add name="sqlcn" connectionstring="___________Connection string"/>
</connectionstring>
----C# file----
using System.Configuration
string c = ConfigurationManager.ConnectionStrings["sqlcn"].ConnectionString; (define it globally)
Operating System provides security to their resources by using authentication & authorization. These two
concepts are used in ASP.Net to implement security.
Authentication
The process of verifieng user credential against specified data source is called as authentication.
Authorization
The process of allocating proper resourcesis performed by authorization.
Authentication has 3 types:
1. Windows Authentication- Used for Intranet Application
2. Passport Authentication
3. Forms Authentication- Used for Internet Application
Windows Authentication:
Client Request to access IIS Server WAT (Windows Authentication Ticket
view secured pages
verify
login DB
Passport Authentication:
Request to access
Verify
IIS server
User View pages by PAT
fir y
ev ot
ytir
Log
in W
oh
ind
tua
ow
Match/authenticate
Third Party
provide PAT(Passport
Authentication Ticket DB
IIS
Server
Request to access
secured pages
DB
namespace Secured_Application
{
public partial class empreg : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public string CreatePassword(int length)
{
const string valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
StringBuilder res = new StringBuilder();
Random rnd = new Random();
while (0 < length--)
{
res.Append(valid[rnd.Next(valid.Length)]);
}
return res.ToString();
}
}
}
}
How to fetch Image from Database / server in ASP.Net
_______________________________
With the help of cookies We can generate Ticket to access secured pages by verifying identity.
To generate cookies in ASP.Net we use HttpCookie class which is present in System namespace.
Persistance cookies: It is stored in browser till its set timing. When the timing end it will be destroyed.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Data.SqlClient;
using System.Configuration;
namespace Secured_Application
{
public partial class Login_Page : System.Web.UI.Page
{
string c = ConfigurationManager.ConnectionStrings["sqlcn"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
Secured page code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Secured_Application.Userhomepage
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Cookies["mycookie"]!=null)
{
Label1.Text = Request.Cookies["mycookie"].Value;
}
else
{
Response.Redirect("~/login.aspx");
}
}
}
}
01/03/2024
How to Destroy cookies in ASP.Net
DrawBack Of cookies
1- Less Secure
2- It uses client storage
3- Large amount of data we can not store in Cookies
Session in ASP.Net
1--
protected void Button1_Click(object sender, EventArgs e)
{
if(.............)
Session["mycookie"]=TextBox1.Text;
Response.Redirect("~/user/user_home.aspx");
}
2--
if(Session["mycookie"]!=null)
{
Label1.Text=Session["mycookie"].ToString
}
namespace Secured_Application.Userhomepage
{
public partial class Userhome : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["mycookie"] != null)
{
Label1.Text = Session["mycookie"].ToString();
Session.Timeout = 1; //minutes.. 20 min
}
else
{
Response.Redirect("~/login.aspx");
}
}
}
}
namespace Secured_Application
{
public partial class Login : System.Web.UI.Page
{
//string c = ConfigurationManager.ConnectionStrings["sqlcn"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
Response.Redirect("~/Userhomepage/userhome.aspx");
}
else
{
Response.Write("Invalid User");
}
}
}
}