1 / 18

Session 14

Session 14. Configuring an ASP.net Application. Session Objectives. Discuss:. Machine.Config. Web.Config. Structure of a configuration file. Secure your web pages using Authentication. Web Pages – Web Application. Web Page. Web Page. Web Page. WEB APPLICATION. Web Page. Web Page

ariel-moss
Télécharger la présentation

Session 14

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Session 14 Configuring an ASP.net Application Building Applications using ASP.NET and C# / Session 14 / 1 of 18

  2. Session Objectives • Discuss: • Machine.Config • Web.Config • Structure of a configuration file • Secure your web pages using Authentication Building Applications using ASP.NET and C# / Session 14 / 2 of 18

  3. Web Pages – Web Application Web Page Web Page Web Page WEB APPLICATION Web Page Web Page --------- --------- Building Applications using ASP.NET and C# / Session 14 / 3 of 18

  4. Configuration Files <configuration> <system.web> <sessionState timeout=”10” /> </system.web> </configuration> • Stored in plain text format Tag and attribute names • Written in XML. Rules for • naming tags and attributes Attribute values • No need to restart server in case of changes to file F E A T U R E S • Each directory can have its own file • Each directory overrides earlier configuration file • Clients cannot view the file from browser Building Applications using ASP.NET and C# / Session 14 / 4 of 18

  5. Types of Configuration Files - 1 Machine.config • Settings are applied to all the applications residing on the server Build number of .net CLR • XML based file • Stored in C:\WinNT\Microsoft.NET\Framework\v.1.xxxx\config • Only one file per ASP.net installation on a machine Web.config • Settings are applied to single application residing on the server • XML based file • One file per each directory of the web application Building Applications using ASP.NET and C# / Session 14 / 5 of 18

  6. Types of Configuration Files - 2 • One per machine Web Applications • One per application • Override settings of machine.config Building Applications using ASP.NET and C# / Session 14 / 6 of 18

  7. Typical Web.config File Configuration section Handler Declaration Area <configuration> <configSections> <section name="sectionSettings" type="Class" /> <sectionGroup name="sectionGroup"> <section name="sectionSettings" type="Class" /> </sectionGroup> </configSections> <section name=”sectionSettings” type=<Class>” /> <sectionGroup> <sectionSettings attribute="someValue" /> <sectionSettings SomeAttribute=”SomeValue”> <element attribute=”value”> </sectionSettings> </sectionGroup> </configuration> Configuration section Settings Area Building Applications using ASP.NET and C# / Session 14 / 7 of 18

  8. Page Configuration Setting Response to the client can be buffered <configuration> <system.web> <pages buffer=”false” enableViewState=”true” /> </system.web> </configuration> View state can be set Building Applications using ASP.NET and C# / Session 14 / 8 of 18

  9. Application Setting Configuration settings in form of key-value pair <configuration> <appSettings> <add key=”MyQuery” value=”Select * FROM MyTable”/> </appSettings> </configuration> The settings are read in ASP.NET page ... String GetQuery = Configuration.AppSettings(“MyQuery”); ... Building Applications using ASP.NET and C# / Session 14 / 9 of 18

  10. Compilation Setting Specifies whether to compile retail binaries or debug binaries. <configuration> <system.web> <compilation debug="true" defaultLanguage=”C#”/> </system.web> </configuration> Provides a semicolon-separated list of language names to use in dynamic compilation of files Building Applications using ASP.NET and C# / Session 14 / 10 of 18

  11. Sub-tags of Compilation tag -1 1 <assemblies> sub-tag add remove clear <configuration> <system.web> <compilation debug="true" defaultLanguage=”C#”/> <assemblies> <add assembly="System.Net" /> </assemblies> </system.web> </configuration> Building Applications using ASP.NET and C# / Session 14 / 11 of 18

  12. Sub-tags of Compilation tag - 2 2 <namespaces> sub-tag <configuration> <system.web> <compilation debug="true" defaultLanguage=”C#”/> <namespaces> <add namespace="System.Web.UI" /> </namespaces> </system.web> </configuration> 3 <compilers> sub-tag Building Applications using ASP.NET and C# / Session 14 / 12 of 18

  13. customErrors Setting <customErrors defaultRedirect="url" mode="On|Off|RemoteOnly"> <error statusCode="statuscode"redirect="url“/> </customErrors> Syntax <configuration> <system.web> <customErrors defaultRedirect="http://localhost/allError.aspx" mode="RemoteOnly"> <error statusCode="404" redirect=“http://localhost/Error404.aspx"/> </customErrors> </system.web> </configuration> Example Building Applications using ASP.NET and C# / Session 14 / 13 of 18

  14. Authentication and Authorization -1 <configuration> <system.web> <authentication mode="Windows|Forms|Passport|None"> <forms name="name" loginUrl="url" protection="All|None|Encryption " timeout="xx" path="/" > <credentialspasswordFormat="Clear|SHA1|MD5"> <user name="username" password="password" /> </credentials> </forms>  <passport redirectUrl="internal"/> </authentication> </system.web> </configuration> Building Applications using ASP.NET and C# / Session 14 / 14 of 18

  15. Authentication and Authorization - 2 Authentication Type Description Windows Windows authentication as default authentication mode. Used for any form of IIS authentication ASP.NET forms-based authentication as default authentication mode Forms Microsoft Passport authentication as default authentication mode Passport No authentication. Used by anonymous users and applications providing own authentication None Building Applications using ASP.NET and C# / Session 14 / 15 of 18

  16. Attributes of <forms> tag Building Applications using ASP.NET and C# / Session 14 / 16 of 18

  17. Forms Authentication <configuration> <system.web> <authentication mode="Forms"> <forms name="form1" loginUrl="login.aspx" protection="None" timeout="60">   <credentials passwordFormat="Clear"> <user name="zeal" password="SaysYahoo"/> <user name="scooby" password="doo"/> <user name="cow" password="moo"/> </credentials>   </forms> </authentication> </system.web> </configuration> Building Applications using ASP.NET and C# / Session 14 / 17 of 18

  18. Authorization <configuration> <system.web> <authentication mode="Forms"> <forms name="form1” loginUrl="login.aspx" protection="None" timeout="60">   <credentials passwordFormat="Clear"> <user name="zeal" password="SaysYahoo"/> <user name="scooby" password="doo"/> <user name="cow" password="moo"/> </credentials>   </forms> </authentication> <authorization> <allow users=”scooby, cow” /> <deny users=”zeal” /> </authorization> </system.web> </configuration> Building Applications using ASP.NET and C# / Session 14 / 18 of 18

More Related