Learn Database Testing

36
8/14/2019 Learn Database Testing http://slidepdf.com/reader/full/learn-database-testing 1/36 Softsmith Infotech .Net Table of contents Introduction to VS 2005 Application and Page Frameworks GUI Controls Validation Server Controls Working with Master Pages Themes & Skins Collections & Lists Data Binding Data Management with ADO.Net Working with XML Site Navigation Security State Management Caching Debugging & Error Handling File I/O & Streams Configurations

Transcript of Learn Database Testing

Page 1: Learn Database Testing

8/14/2019 Learn Database Testing

http://slidepdf.com/reader/full/learn-database-testing 1/36

Softsmith Infotech

.Net

Table of contents• Introduction to VS 2005• Application and Page Frameworks• GUI Controls• Validation Server Controls• Working with Master Pages• Themes & Skins• Collections & Lists

• Data Binding• Data Management with ADO.Net• Working with XML• Site Navigation• Security• State Management• Caching• Debugging & Error Handling• File I/O & Streams• Configurations

Page 2: Learn Database Testing

8/14/2019 Learn Database Testing

http://slidepdf.com/reader/full/learn-database-testing 2/36

Softsmith Infotech

Site Navigation

• We can access an aspx web applicationby means of virtual path.

http://localhost/VirtualDirectoryName/Default.aspx

If Default.aspx file exists in the application, this

URL would open the file in browser.We can also give any other valid aspx file namein the browser to view that file

Page 3: Learn Database Testing

8/14/2019 Learn Database Testing

http://slidepdf.com/reader/full/learn-database-testing 3/36

Softsmith Infotech

Security

• Threats faced by an application

 – Spoofing

 – Tampering

 – Repudiation

 – Information disclosure

 – Denial of Service

 – Elevation of privilege

Page 4: Learn Database Testing

8/14/2019 Learn Database Testing

http://slidepdf.com/reader/full/learn-database-testing 4/36

Softsmith Infotech

Security in ASP .Net

• Security in the context of ASP.NET applicationinvolves 3 fundamental terms

• Authentication

 – is the process of identifying users who can use theapplication (password checking)

• Authorization– Defining what operations the users can do and

to what level (access rights check)• Impersonation 

– This is the technique used by a serverapplication to access resources on behalf of aclient

Page 5: Learn Database Testing

8/14/2019 Learn Database Testing

http://slidepdf.com/reader/full/learn-database-testing 5/36

Softsmith Infotech

Authentication

• Authentication Modes

 – Windows Authentication – IIS authentication

 – Forms Authentication - Application credential

verification – Microsoft Passport Authentication

• Specifying Authentication Mode

 – Can be specified in the Web.config file as follows

 <authentication mode=“Windows" /> 

 <authentication mode=“Forms" /> 

 <authentication mode=“Passport" /> 

Page 6: Learn Database Testing

8/14/2019 Learn Database Testing

http://slidepdf.com/reader/full/learn-database-testing 6/36

Softsmith Infotech

IIS Authentication

• Basic

 – IIS instructs the browser to send the user's credentials over HTTP

 – Credentials are Base64 encoded which are not that much secure

• Digest

 – Digest authentication sends credentials across the network as a Message

Digest 5 (MD5) hash (encrypted)

• Integrated Windows (Used in large organisation connected with Network)

 – Uses either NTLM challenge/response or Kerberos to authenticate users with a

Windows NT Domain or Active Directory account

 – A Hash of the credentials is sent, password is encrypted and sent

• .NET Passport – The credentials that are registered with Microsoft which can be used with any

microsoft application like – hotmail, msn messenger or skydrive or windows Live

etc

Page 7: Learn Database Testing

8/14/2019 Learn Database Testing

http://slidepdf.com/reader/full/learn-database-testing 7/36

Softsmith Infotech

Authorization

• We can allow or deny Users using authorization tag in web.config

file

 <authorization> 

<deny users="?"></deny> 

<allow users="*" />  <!-- Allow all users -->    <!--

 <allow users="[comma separated list of users]"

roles="[comma separated list of roles]"/> 

   <deny users="[comma separated list of users]"

roles="[comma separated list of roles]"/> --> 

 </authorization> 

Page 8: Learn Database Testing

8/14/2019 Learn Database Testing

http://slidepdf.com/reader/full/learn-database-testing 8/36

Softsmith Infotech

Forms Authentication

• Can store credentials in web.config files

• For Login page, only if given the following

credentials it will allow. <authentication mode="Forms"> 

 <forms name="Login" loginUrl="Login.aspx"> 

<credentials passwordFormat="Clear"> 

 <user name="smith" password="manager"></user> 

<user name="Smith" password="manager"></user> </credentials> 

</forms> 

</authentication> 

Page 9: Learn Database Testing

8/14/2019 Learn Database Testing

http://slidepdf.com/reader/full/learn-database-testing 9/36

Softsmith Infotech

State Management

• Web forms are created and destroyed each time a client makes a request

• Page state is not retained

 – For postbacks

 – Between pages

• State management is implemented using

 – Client side options• Viewstate

• Cookies

• QueryString

 – Server side options• Application

• Session

• Database support

Page 10: Learn Database Testing

8/14/2019 Learn Database Testing

http://slidepdf.com/reader/full/learn-database-testing 10/36

Softsmith Infotech

View State

• Stores information as hidden fields

• ViewState is enabled for every page by default

• Saving Arraylist in a view state

protected void Page_PreRender(object sender, EventArgs e)

{

  ViewState.Add("arrayListInViewState", PageArrayList);

}

We can access the same as follows

ViewState[“arrayListInViewState”]

Page 11: Learn Database Testing

8/14/2019 Learn Database Testing

http://slidepdf.com/reader/full/learn-database-testing 11/36

Softsmith Infotech

Cookies

• To store small amounts of information on a client

• To store user-specific information

• Store as key/value pair 

//Create a cookie

HttpCookie uname = new HttpCookie("UserName");

uname.Value = txtUser.Text;//Add the cookie

Response.Cookies.Add(uname);

//Set the Expiry date for the cookie

Response.Cookies["UserName"].Expires = d1.AddYears(2);

//Retrive the value of cookieif(Request.Cookies["UserName"] != null) {

//Display the value of cookie

lblUser.Text = Request.Cookies["UserName"].Value;

}

Page 12: Learn Database Testing

8/14/2019 Learn Database Testing

http://slidepdf.com/reader/full/learn-database-testing 12/36

Softsmith Infotech

Query string

• Easy way to pass information

 – Between pages

• Way to pack information with URL

• The URL with a query string look like below

http://localhost/Demo/Default.aspx?Uname=“guest”

To send page data as query string

 Response.Redirect("welcome.aspx?category="+txtCategory.Text)

To retrieve data in next page

lblCategory.Text=“We welcome” +

Request.QueryString[“category”];

Page 13: Learn Database Testing

8/14/2019 Learn Database Testing

http://slidepdf.com/reader/full/learn-database-testing 13/36

Softsmith Infotech

Session

 – Can store information that we want to keep local to the current session

(single user)

 – We can store values that need to be persisted for the duration of a user 

 – Every user session will be assigned a unique SessionId

 protected void Session_Start(Object sender, EventArgs e)

{

Session["userName"] =“guest";

}

 protected void Session_End(Object sender, EventArgs e){

Session.Remove("userName");

}

Page 14: Learn Database Testing

8/14/2019 Learn Database Testing

http://slidepdf.com/reader/full/learn-database-testing 14/36

Softsmith Infotech

Session State

• Session state can be stored in three ways

 – InProc• Stores session data in the memory of the ASP.NET worker process

• Provides faster access to these values

• Session data is lost when the ASP.NET worker process is recycled

• Need to give in the Web.config file as follows

 <sessionState mode="InProc“/> 

 – StateServer • Uses a stand alone window service (State Server) to store session variables

 – Independent of IIS as it can run as separate service

• Better load balancing management as clustered servers can share their session

information

• Need to give in the Web.config file as follows

 <sessionState mode=" StateServer“/> 

Page 15: Learn Database Testing

8/14/2019 Learn Database Testing

http://slidepdf.com/reader/full/learn-database-testing 15/36

Softsmith Infotech

Session State

 – SQLServer • Similar to State Server, except that the information persists in MS-SQL

Server database tables

• Need to give the following in Web.config file

 <sessionState mode=“SQLServer“/> 

• Note: To use SQL Server as session state store, create the necessary

tables and stored procedures

• .NET SDK provides us with a SQL script InstallPersistSqlState.sql

Page 16: Learn Database Testing

8/14/2019 Learn Database Testing

http://slidepdf.com/reader/full/learn-database-testing 16/36

Softsmith Infotech

Application

• Provides a mechanism for storing data that is accessible to all users using

the Web Application

• Are declared in a special file called as Global.asax

 void Application_Start() {

 Application["startTime"] = DateTime.Now.ToString();

}

 void Application_End() {

Application["startTime"] = null;

}

Page 17: Learn Database Testing

8/14/2019 Learn Database Testing

http://slidepdf.com/reader/full/learn-database-testing 17/36

Softsmith Infotech

Database Support

• Database support may be used to maintain state of your Web site

• Advantages of Using a Database to Maintain State

 – Security

 – Storage capacity – Data persistence

 – Robustness and data integrity

 – Accessibility

 – Widespread support

• Disadvantages of Using a Database to Maintain State

 – Complexity

 – Performance considerations

Page 18: Learn Database Testing

8/14/2019 Learn Database Testing

http://slidepdf.com/reader/full/learn-database-testing 18/36

Softsmith Infotech

Caching

 – In ASP.NET, page gets processed and is

destroyed for every request

 – Some times, dynamic contents of page may

not change frequently

 – ASP.NET holds such content in memory so

that it can be delivered again efficientlywithout processing

Page 19: Learn Database Testing

8/14/2019 Learn Database Testing

http://slidepdf.com/reader/full/learn-database-testing 19/36

Softsmith Infotech

Caching – Single Response

• Use the @OutputCache page directive to cache a Web form in the

server’s memory

 – The Duration attribute of @OutputCache directive’s controls

how long the page is cached.

• Setting VaryByParam="None” caches only one version of the webform

// Web form is Cached for 60 seconds

 <%@ OutputCache Duration="60" VaryByParam="None" %> 

Page 20: Learn Database Testing

8/14/2019 Learn Database Testing

http://slidepdf.com/reader/full/learn-database-testing 20/36

Softsmith Infotech

Caching – Multiple Response

//This page sends item (Infopage.aspx)

 private void btnSubmit_Click(object sender,System.EventArgs e)

{

Response.Redirect("NextPageVaryParam.aspx?id="+drpTimeZone.SelectedItem);

}

// Web form is Cached for dropdownlistbox selected item 

//This page is cached depend on item selected from 

//infopage.aspx <%@ OutputCache Duration="60" VaryByParam=“id" %> 

Page 21: Learn Database Testing

8/14/2019 Learn Database Testing

http://slidepdf.com/reader/full/learn-database-testing 21/36

Softsmith Infotech

Fragment Cache

• Cache regions of a page content

• Attribute used

 – @ OutputCache

 – VaryByParam -varies cached results based on name/value pairs sent

using POST or GET 

 – VaryByControl -varies the cached fragment by controls within the user 

control

 <%@ OutputCache Duration="120" VaryByParam="none"

 VaryByControl="Category" %> 

Page 22: Learn Database Testing

8/14/2019 Learn Database Testing

http://slidepdf.com/reader/full/learn-database-testing 22/36

Softsmith Infotech

Data Caching

• Data caching is storing of data internal to a web application

• This enables to use the cached object across all the pages of the

application

• Cache is global to entire web application and is accessible to all the

clients of that application• The lifetime of such cached objects is that of the application itself 

• If the application is restarted then all the cached objects are

destroyed

• Expiry time can be set for cache objects

 – Absolute Expiry (Absolute value)

 – Sliding Expiry (relative value – from now onwards 5 seconds)

Page 23: Learn Database Testing

8/14/2019 Learn Database Testing

http://slidepdf.com/reader/full/learn-database-testing 23/36

Softsmith Infotech

Debugging

• Visual studio 2005 provides a built in

debugger.

• Breakpoint – Press F9 to insert break

point at a location or Select Insert Break

Point from Debug Menu

• We can Step Over using (F10 key) or Step

Into using (F11 key) a function

Page 24: Learn Database Testing

8/14/2019 Learn Database Testing

http://slidepdf.com/reader/full/learn-database-testing 24/36

Softsmith Infotech

Error Handling

• .NET CLR provides structured Exception handling

 – Using try catch block

• ASP.NET provides declarative error handling

 – Automatically redirect users to error page when unhandled exceptionsoccur 

 – Prevents ugly error messages from being sent to usersThe Web.Config should have these lines

 <configuration> 

 <customErrors mode=“On” defaultRedirect=“error.htm”> 

<error statusCode=“404” redirect=“adminmessage.htm”/> 

<error statusCode=“403”redirect=“noaccessallowed.htm”/> 

</customErrors> 

 </configuration> 

Page 25: Learn Database Testing

8/14/2019 Learn Database Testing

http://slidepdf.com/reader/full/learn-database-testing 25/36

Softsmith Infotech

Error Handling

• The mode attribute can be one of the following:

 – On • Error details are not shown to anybody, even local users

• If you specify a custom error page it will be always used

 – Off • Everyone will see error details, both local and remote users

• If you specify a custom error page it will NOT be displayed

 – RemoteOnly • Local users will see detailed error pages

• Remote users will be presented with a concise page notifying themthat an error occurred

• Note : Local user means User browsing the site on the same machinewhere web applications are deployed

Page 26: Learn Database Testing

8/14/2019 Learn Database Testing

http://slidepdf.com/reader/full/learn-database-testing 26/36

Softsmith Infotech

File Handling

• System.IO name space will have Methods

and classes for File Handling

• FileInfo and DirectoryInfo class helps us in

managing files and directory

• Both these classes are inherited from

FileSystemInfo class

Page 27: Learn Database Testing

8/14/2019 Learn Database Testing

http://slidepdf.com/reader/full/learn-database-testing 27/36

Softsmith Infotech

FileSystemInfo

• Used to discover general characteristics about agiven file or directory.

• Properties

- Attributes- Creation Time

- Exists

- Extension

- Full Name- Last Access Time

- Last Write time

- Name

Page 28: Learn Database Testing

8/14/2019 Learn Database Testing

http://slidepdf.com/reader/full/learn-database-testing 28/36

Softsmith Infotech

FileInfo

• Methods

- AppendText() - MoveTo()

- CopyTo() - Open()

- Create() - OpenRead()

- CreateText() - OpenText()- Delete() - OpenWrite()

• Properties

- Directory- DirectoryName

- Length

- Name

Page 29: Learn Database Testing

8/14/2019 Learn Database Testing

http://slidepdf.com/reader/full/learn-database-testing 29/36

Softsmith Infotech

FileInfo Example

FileInfo FI = new FileInfo(@"form1.cs“)

MessageBox.Show(FI.DirectoryName.ToString());

MessageBox.Show(FI.Extension.ToString());

MessageBox.Show(FI.LastAccessTime.ToString());

MessageBox.Show(FI.LastWriteTime.ToString());

Page 30: Learn Database Testing

8/14/2019 Learn Database Testing

http://slidepdf.com/reader/full/learn-database-testing 30/36

Softsmith Infotech

Streams

• Streams are channels of communication between programs and

source/destination of data

 – A stream is either a source of bytes or a destination for bytes.

• Provide a good abstraction between the source and destination

• Abstract away the details of the communication path from I/Ooperation

• Streams hide the details of what happens to the data inside the

actual I/O devices.

• Streams can read/write data from/to blocks of memory, files and

network connections

• Stream can be File or Console or Network or Hardware

Page 31: Learn Database Testing

8/14/2019 Learn Database Testing

http://slidepdf.com/reader/full/learn-database-testing 31/36

Softsmith Infotech

Stream

• Byte Stream

 – FileStream – Works with File

 – MemoryStream – Works with array

 – BufferedStream - Optimized read/write operations

• Character Stream

 – TextReader 

 – TextWriter 

Page 32: Learn Database Testing

8/14/2019 Learn Database Testing

http://slidepdf.com/reader/full/learn-database-testing 32/36

Softsmith Infotech

Byte Stream

• FileStream class is used to read from, write to, open, and close

files on a file system

• The MemoryStream class creates streams that have memory as a

backing store instead of a disk or a network connection – encapsulates data stored as an byte array

• BufferedStream

 – A buffer is a block of bytes in memory used to cache data

 – reduces the number of calls to the operating system

 – Buffers improve read and write performance.

Page 33: Learn Database Testing

8/14/2019 Learn Database Testing

http://slidepdf.com/reader/full/learn-database-testing 33/36

Softsmith Infotech

Character Stream

• Both are abstract classes used read and write data using charactersfrom different streams

• TextReader 

 – Represents a reader that can read a sequential series of 

characters

• TextWriter 

 – Represents a writer that can write a sequential series of characters

• To read and write we use derived classes like StreamReader andStreamWriter 

Page 34: Learn Database Testing

8/14/2019 Learn Database Testing

http://slidepdf.com/reader/full/learn-database-testing 34/36

Softsmith Infotech

Binary Reader/Writer 

It can be used in the way StreamReader/Writer are used.

The BinaryReader methods

 – bool ReadBoolean()

 – byte ReadByte() – char ReadChar()

 – float ReadSingle()

 – double ReadDouble()

 – int ReadInt32()

The BinaryWriter method

-void Write( any single primitive type argument )

Page 35: Learn Database Testing

8/14/2019 Learn Database Testing

http://slidepdf.com/reader/full/learn-database-testing 35/36

Softsmith Infotech

Configurations

• These two files helps us in setting

configurations

• Machine.Config – Machine level

configuration

• Web.Config – Application level

configuration

Page 36: Learn Database Testing

8/14/2019 Learn Database Testing

http://slidepdf.com/reader/full/learn-database-testing 36/36

Softsmith Infotech

Configurations

• Configuration files can be stored in application folders

 – Configuration system automatically detects changes

• Hierarchical configuration architecture

 – Applies to the actual directory and all subdirectories

Examples:

 <compilation defaultLanguage="c#“ debug="true“/> 

 <sessionState> 

   <!--- sessionstate subelements go here -->  </sessionState>