Journey to MCTS 70-515: Lesson 4 – Master Pages

Developer Featured ImagePrecedence

If a property is set on the content page to true but the same property is set to false in the master page then the setting on the master page takes priority.

Referencing Properties

To reference any master page properties from content pages do the following,

  1. Create a public property in the master page code-behind file.
  2. Add the @MasterType declaration to the ASPX content page.
  3. Reference the master page property from the content page by using the syntax Master.<Property_Name>.

Actual Scenario: -

Question 1:

Default.aspx uses a master page named Site.master. You add the following code to the Default.aspx code-behind file to read a Site.master public property named Username.

protected void Page_Load(object sender, EventArgs e)
{
        string s = Master.Username;
}

You need to ensure that Default.aspx can access the Username property. What should you do?

  1. Add the following directive to Default.aspx.
    <%@ MasterType VirtualPath=”~/Site.master” %>
  2. Add the following directive to Default.aspx.
    <%@ PreviousPageType VirtualPath=”~/Site.master” %>
  3. Set the Strict attribute in the @ Master directive of the Site.master page to true.
  4. Set the Explicit attribute in the @ Master directive of the Site.master page to true.

  

Referencing Controls
Apart from properties, controls can also be referenced and updated in the master page from any content page using the Master.FindControl method. You only need to pass this method the name of the control. Master.FindControl returns a Control object that would need to be casted to the correct control type. After this reference is made, you can read or update the object as if it were local to the content page.

The following code (in the Page_Load method of the content page) updates a Label control named lblWebsite in the master page,

Label MyWebsite = (Label)Master.FindControl("lblWebsite");
MyWebsite.Text = "IRTAZAALI.COM";

 

Dynamically Changing Master Pages
Page_PreInit method is the last opportunity to override the default master page setting. This is because after this event the content page binds with the master page preventing it from being changed.

 

Journey to MCTS 70-515: Lesson 1 – Understanding Web Communications

A Web Server’s Role

A web server provides content while the browser displays it. The web server sends files, html or images, through an HTTP connection to the web browser. The following processes take place when a web server receives a request from a web browser: -

1. Request Verification. Web Servers must be able to verify if the request made is legitimate and not a malformed one. If the latter case exists then the web server ignores the request.

2. SSL Authentication. If a Secure Sockets Layer (SSL) certificate has been applied on the web server and the request was made with HTTPS, the web browser uses that certificate to authenticate the server. All content is encrypted by the web server before returning it to the web browser.

3. User Authentication. If the website requires authorization, the web server verifies if the user has submitted credentials. If the user has not been authenticated then the web server redirects to an authentication form already specified for the website.

4. User Authorization. The user submits login credentials. The web server authenticates the user and verifies if the user is allowed to access the requested content.

5. Handling requests. If the web browser requested static content or was trying to access cached content, the web server can directly respond. But if the web browser requests an ASP.NET page then the request is forwarded to ASP.NET.

6. Error Handling. If a server cannot process the web browser request an error is sent to the web browser. These errors include HTTP status codes.

7. Cache output. Web servers cache output to improve response time of subsequent requests. They also provide caching information to web browsers as to know how long to keep the content cached.

8. Compress output. A web server can compress the content to reduce the bandwidth required before sending the page to the web browser.

9. Logging access. Web servers record usage information for security and performance-monitoring purposes.

The Web Browser’s Role
Following are the actions performed by the web browsers in general: -

1. Sending requests to web server. When url http://www.wordpress.com
is entered the web browser resolves the www.wordpress.com Domain Name System (DNS) address. It then uses HTTP to connect to the server and requests the relevant page, in this that’s the default page.

2. Server Authentication. If the server has an SSL certificate and the request was made with HTTPS, the web browser uses the certificate to authenticate the server and then decrypts future communications.

3. Process the response. If the server sends HTML, the browser retrieves embedded objects, such as images, videos, or animations referenced in the HTML. If the server has sent an error, redirection, or other response, the browser responds appropriately.

4. Displaying HTML and embedded objects. Web browsers use HTML standards to determine how to display a webpage to the user. Because HTML can contain embedded objects, a web browser might have to display dozens of objects to render a single webpage.

5. Run client scripts. Client scripts such as in JavaScript enable interactive and responsive pages without reloading the page.

Understanding the Role of HTTP

HTTP is a text-based communication protocol that is used to request webpages from a web server and send responses back to a web browser. When a webpage is requested, the browser sends a request to the web server.

The request might look like the following:

GET /default.aspx HTTP/1.1

Host: www.microsoft.com

If a website has Distributed Authoring and Versioning (DAV) enabled, many more commands are available, including LOCK and UNLOCK.

Note: WebDAV must be enabled if you want to use source control or versioning database/tool from the webserver. For example a webservice giving access to Visual SourceSafe hosted on the web server.

Follow

Get every new post delivered to your Inbox.