<span class='text_page_counter'>(1)</span><div class='page_container' data-page=1>
Session 19
<b>Configuring an </b>
</div>
<span class='text_page_counter'>(2)</span><div class='page_container' data-page=2>
Review
A service has two characteristics: Interface and Registration.
Web services reduce the “communication-gap” among the Web applications,
enhancing interactivity. Web sites thereby group together to form a
constellation, providing users a rich user experience
Advantages of Web Services
Cross business integration
Improved efficiency
Closer customer relationships
Facilitation of just-in-time integration
The extension of a Web service file in .NET is .asmx.
The [WebMethod] tag notifies the ASP.NET compiler that the method to follow
</div>
<span class='text_page_counter'>(3)</span><div class='page_container' data-page=3>
Exploring ASP.NET / Session 19 / 3 of 31
Review contd..
A Web service could be called from a browser, an ASP page or even another Web
service. Using the browser, the Web service can be accessed using either
HTTP-GET or HTTP-POST. A SOAP request from an ASP page, or a Web service to
another Web service can also be made.
WSDL is the short form for Web Services Description Language. WSDL is the
grammar for a Web service, or moreover, could be thought of as a language that
describes or portrays a Web service.
The proxy class does not contain any application logic. Instead, it contains the
transporting logic as to how the parameters would be passed, and the result
retrieved.
The proxy class will also contain a list of all the methods that are present in the
Web service and their prototypes.
UDDI is the abbreviation for Universal Description, Discovery and Integration.
UDDI helps in registering the services provided by the service providers, so that
</div>
<span class='text_page_counter'>(4)</span><div class='page_container' data-page=4>
Objectives
Discuss Machine.Config
Discuss Web.Config
Discuss the structure of a configuration
file
Secure your web pages using
</div>
<span class='text_page_counter'>(5)</span><div class='page_container' data-page=5>
Web Pages – Web Application
Individual web pages together form a web application
Advantage of grouping individual pages together into an
application, is that values can be set for all these pages at
once, by setting the properties of the application
The setting of values for the properties of an application
that will control the application at runtime, is known as
configuring the ASP.NET application
Web Page
<sub>Web Page </sub>
Web Page
<sub>Web Page </sub>
<b>Web Page </b>
<b>--- </b>
<b>--- </b>
</div>
<span class='text_page_counter'>(6)</span><div class='page_container' data-page=6>
Configuration Files
In ASP.NET, all that needs to be done to configure an
application, is to create a configuration file called
<b>web.config, and place it in the root directory of the </b>
application
This web.config is an XML based file
<configuration>
<system.web>
<sessionState timeout=”20” />
</system.web>
</configuration>
ASP.NET provides the configuration files that are needed to
customize the web site. These files offer remarkable
</div>
<span class='text_page_counter'>(7)</span><div class='page_container' data-page=7>
Features of Configuration Files
Stored in plain text format
Written in XML. Rules for naming tags and
attributes
No need to restart server in case of changes
to file
Each directory overrides earlier
configuration file
</div>
<span class='text_page_counter'>(8)</span><div class='page_container' data-page=8>
Rules for naming the Tags
<b>Type of Tags </b>
<b>Rule </b>
Tag and attribute names
<b>Camel-cased : First character of a tag </b>
name is lowercase, and the first letter
of any subsequent words is uppercase
Attribute values
<b>Pascal-case : first character is </b>
uppercase, and the first letter of any
subsequent concatenated words is
<b>uppercase. Exceptions being true and </b>
</div>
<span class='text_page_counter'>(9)</span><div class='page_container' data-page=9>
Types of Configuration Files
<b>Machine.config </b>
<b> Decides configuration for all the applications residing </b>
<b> on the server </b>
<b> Settings are applied to single application residing on the server </b>
<b> XML based file is </b>
<i><b> Stored in C:\WinNT\Microsoft.NET\Framework\v.1.xxxx\config </b></i>
<b>Build number </b>
<b>of .net CLR </b>
<b>Web.config </b>
<b> Only one file per ASP.NET installation on a machine </b>
<b> XML based file stored in the web application directory of the </b>
<b>web server </b>
</div>
<span class='text_page_counter'>(10)</span><div class='page_container' data-page=10>
Types of Configuration Files –
Contd…
<b>Web </b>
<b>Applications </b>
<b> One per machine </b>
<b>One per application </b>
<b>Override settings of </b>
</div>
<span class='text_page_counter'>(11)</span><div class='page_container' data-page=11>
Structure of Configuration
Files
The configuration file encloses all the tags within the
configuration tags, which if not done, the compiler
throws an exception
The configuration properties of the machine are set
between these tags
Within the configuration tags, the configuration
information is grouped into two categories:
configuration section handler declaration area
configuration section settings area
Configuration sections are defined between
<b><configSections> and </configSections> tags </b>
The individual sections are defined using the
</div>
<span class='text_page_counter'>(12)</span><div class='page_container' data-page=12>
Typical Web.config File
<configuration>
<b> <configSections> </b>
<section name="sectionSettings" type="Class" />
<sectionGroup name="sectionGroup">
<section name="sectionSettings" type="Class" />
</sectionGroup>
<b> </configSections> </b>
<b> <section name=”sectionSettings” type=<Class>” /> </b>
<sectionGroup>
<b> <sectionSettings attribute="someValue" /> </b>
<b> <sectionSettings SomeAttribute=”SomeValue”> </b>
<element attribute=”value”/>
<b> </sectionSettings> </b>
</sectionGroup>
</div>
<span class='text_page_counter'>(13)</span><div class='page_container' data-page=13>
Configuration Section Handler
Declaration Area
Defines a class (usually a .NET base class) that
will be used to interpret the configuration data
This section is enclosed between the
<configSections> tag
Generally, this section is placed in the
Machine.Config file, and need not be placed in
each and every Web.Config file, as it will be
</div>
<span class='text_page_counter'>(14)</span><div class='page_container' data-page=14>
Configuration Sections Settings
Area
Defines the actual settings for some particular
option
Contains the section handlers in which the
configuration code is written
Each of the section handlers is grouped in a
<sectionGroup>, that offers a structure to
the configuration file
</div>
<span class='text_page_counter'>(15)</span><div class='page_container' data-page=15>
Page Configuration Settings
<configuration>
<system.web>
<b> <pages buffer=”true” </b>
<b> enableViewState=”false” /> </b>
</system.web>
</configuration>
The page configuration settings allow the developer to control some
of the default behaviors for all the ASP.NET pages in the application
or machine
<b>Property </b>
<b>Description </b>
<b>Default Value </b>
Buffer Sets whether the response to a client is sent
directly, or is first buffered on the server and then
sent.
True
enableView
State
Sets whether ViewState is to be enabled or
disabled
</div>
<span class='text_page_counter'>(16)</span><div class='page_container' data-page=16>
Application Setting
The application settings section is enclosed between the
<appSettings> and </appSettings> tags.
These settings allow the user to set the application configuration
details.
Application settings enable to store and retrieve information as
key-value pairs
It is also possible to store, SQL queries
<configuration>
<b> <appSettings> </b>
<b> <add key=”MySQLQuery” value=”Select * FROM MySQLTable”/> </b>
<b> </appSettings> </b>
</configuration>
...
</div>
<span class='text_page_counter'>(17)</span><div class='page_container' data-page=17>
Compilation Setting
The compilation settings section is used to specify the compilation options that
are necessary to compile the application source files.
References of the assemblies that are required during compilation can be
specified here
It is also possible to specify whether to run the application in a debug mode
<b>Attribute </b>
<b>Option </b>
<b>Description </b>
Debug <sub>Specifies whether to compile retail binaries or </sub>
debug binaries.
true Specifies compilation of debug binaries.
false Specifies compilation of retail binaries.
</div>
<span class='text_page_counter'>(18)</span><div class='page_container' data-page=18>
Compilation Setting
Configuration
<configuration>
<system.web>
<compilation
<b> debug=“false" </b>
<b> defaultLanguage=”C#”/> </b>
</system.web>
</configuration>
</div>
<span class='text_page_counter'>(19)</span><div class='page_container' data-page=19>
Sub-tags of Compilation tag
<configuration>
<system.web>
<compilation
debug=“true” defaultLanguage=“C#”>
<assemblies>
<i><b> <add assembly="System.Data" /> </b></i>
</assemblies>
</compilation>
</system.web>
</configuration>
<b><add> </b>
<b><sub><remove> </sub></b>
<b><clear> </b>
</div>
<span class='text_page_counter'>(20)</span><div class='page_container' data-page=20>
Sub-tags of Compilation tag
Contd…
<configuration>
<system.web>
<compilation
debug=“true” defaultLanguage=“C#”>
<namespaces>
<i> <add namespace=“System.Web.UI” /> </i>
</namespaces>
</compilation>
</system.web>
</configuration>
</div>
<span class='text_page_counter'>(21)</span><div class='page_container' data-page=21>
Sub-tags of Compilation tag
Contd…
<b><compilers> sub-tag </b>
</div>
<span class='text_page_counter'>(22)</span><div class='page_container' data-page=22>
customErrors Setting
ASP.NET provides the flexibility to write custom error
pages, and redirect the browser (client) to these error
pages when any specific error occurs
The error pages to be displayed can be designed to give
a more polite and user-friendly explanation of the error
and its cause.
<i><customErrors </i>
<i> defaultRedirect="url" </i>
<i> mode="On|Off|RemoteOnly"> </i>
<i> <error statusCode="statuscode" redirect="url“/> </i>
</customErrors>
</div>
<span class='text_page_counter'>(23)</span><div class='page_container' data-page=23>
customErrors Example
<configuration>
<b> <system.web> </b>
<b> <customErrors defaultRedirect= "http:// </b>
localhost/Appdir/allErrors.aspx"
mode="RemoteOnly">
<error statusCode="404"
redirect=" http:// localhost/ Appdir/
ErrorNo404.aspx"/>
</customErrors>
</system.web>
</div>
<span class='text_page_counter'>(24)</span><div class='page_container' data-page=24>
Authentication
<configuration>
<system.web>
<i><b> <authentication mode="Windows|Forms|Passport|None"> </b></i>
<i><b> <forms name="name" loginUrl="url" </b></i>
<i><b> protection="All|None|Encryption " </b></i>
<b> timeout="xx" path="/" > </b>
<b> <credentials passwordFormat="Clear|SHA1|MD5"> </b>
<b> <user name="username" password="password" /> </b>
<b> </credentials> </b>
<b> </forms> </b>
<b> <passport redirectUrl="internal"/> </b>
<b> </authentication> </b>
</system.web>
The process of identifying the valid user/password, and providing services
</div>
<span class='text_page_counter'>(25)</span><div class='page_container' data-page=25>
Authentication Types
<b>Specifies Windows authentication as </b>
<b>default authentication mode. Used for </b>
<b>any form of IIS authentication </b>
<b>Specifies ASP.NET forms-based </b>
<b>authentication as default authentication </b>
<b>mode. Widely used method </b>
<b>Specifies Microsoft Passport </b>
<b>authentication as default </b>
<b>authentication mode </b>
<b>No authentication. Used by </b>
<b>anonymous users and applications </b>
<b>providing own authentication </b>
WINDOWS
FORMS
</div>
<span class='text_page_counter'>(26)</span><div class='page_container' data-page=26>
Attributes of <forms> tag
<b>Attribute Option </b> <b>Description </b>
<b>Name </b> None Cookie name used for authentication
<b>LoginUrl None </b> Login page URL. The client is redirected to this URL if
no authentication cookie
<b>protection Encryption Cookie should not be stored as plain text but should be </b>
encrypted for protection.
<b>Validation Validation scheme verifies whether the contents of </b>
an encrypted cookie have been altered in transit
ALL Application uses both data validation and encryption to
protect the cookie.
None Both encryption and validation are disabled
To use Form Authentication, the authentication mode needs to be specified as
<b>Forms, in which case the <forms> sub-tag can be supplied having following </b>
</div>
<span class='text_page_counter'>(27)</span><div class='page_container' data-page=27>
Attributes of <forms> tag
<b>Attribute Option </b> <b>Description </b>
<b>timeout </b> The amount of time, in minutes, after which the
authentication cookie expires. Default value is 30.
</div>
<span class='text_page_counter'>(28)</span><div class='page_container' data-page=28>
Forms Authentication Example
<configuration>
<system.web>
<authentication mode="Forms">
<forms name="MainForm"
loginUrl="LoginPage.aspx"
protection="None" timeout="60">
<credentials passwordFormat="Clear">
<user name="User1" password="user1!"/>
<user name="User2" password="user2@"/>
<user name="User3" password="user3#"/>
</credentials>
</forms>
</authentication>
</system.web>
</div>
<span class='text_page_counter'>(29)</span><div class='page_container' data-page=29>
Authorization
After setting the authentication settings for an
application, access rights need to be assigned
as to who can access the application
Setting these access rights is known as
Authorization
Using Authorization settings, users are actually
authorized to access the website
<authorization>
</div>
<span class='text_page_counter'>(30)</span><div class='page_container' data-page=30>
Authorization Example
<configuration> <system.web>
<authentication mode="Forms">
<forms name="MainForm” loginUrl="LoginPage.aspx"
protection="None" timeout="60">
<credentials passwordFormat="Clear">
<user name="User1" password="user1!"/>
<user name="User2" password="user2@"/>
<user name="User3" password="user3#"/>
</credentials>
</forms>
<b> </authentication> </b>
<b> <authorization> </b>
<b> <allow users=”User2, User3” /> </b>
<b> <deny users=”User1” /> </b>
<b> </authorization> </b>
</div>
<span class='text_page_counter'>(31)</span><div class='page_container' data-page=31>
Summary
ASP.NET is a collection of all the ASP.NET pages, the custom
controls and modules
It provides the configuration files to customize the web site.
The ASP.NET configuration files are written in XML, which enables
the developer to modify them using an XML parser.
Two types of configuration files exist in ASP.NET:
<b>Machine.Config </b>
<b>Web.Config </b>
A hierarchical structure can be formed with every directory,
</div>
<span class='text_page_counter'>(32)</span><div class='page_container' data-page=32>
Summary Contd…
Within the configuration tags, the configuration information is
grouped into two categories:
<b>The configuration section handler declaration area </b>
<b>The configuration section settings area. </b>
The process of validating the user name and password is known as
</div>
<!--links-->