Malaika Consultants LLC

Step 4: ASP.NET Master Pages

by Jane Thomson 1. May 2011 23:27

ASP.Net Master Pages are one of the recent features added in ASP.Net. This feature allows a user to apply same kind of page layout to all the pages of the web application or a website. A web page which uses the master page is also known as the content page. Previously, there was consistent issue faced by users regarding not to have a feature that allow users to give a consistent look across multiple web pages of a single website. ASP.Net master pages are created to take care of deficiency in .NET.

In a website, you can find number of features same across multiple web pages of a single website such as copyright notices, menus, logos etc. Also, a website has a single layout design. Sometimes, even the control buttons across the web pages remains same. In such condition, Master pages take the control to apply same features across the multiple web pages.

Usually, the master page is differentiated by @Master directive which takes place of the directive @page which is used in the pages which are not the part of master pages. The master directive looks something like below:

<%@ Master Language="VB" %>

The directive @Master can contain almost the same directives which @Control directive can. I.e. below master page directive contains the name of the code file and allocates a class name for the master page.

<%@ Master Language="VB" CodeFile="MasterPageexam.masterexam.vb" Inherits="MasterPageexam" %>

In addition to above elements, @Master directive can also contains the top level HTML elements such as head, html tag, form tag etc. for a web page. I.e. user can use the html table tag and image tag to include table and image in the web page. User is allowed to use all the elements of ASP.NET and HTML as a part of the master page. This means ASP.NET master page is a well organized feature for the ASP.NET users to have same look and feel across multiple web pages with a little effort.

 

For Step 5 please click here.

Tags:

Coding

ASP.NET Caching – A Primer : Part 2 – Partial Page Caching

by Swanand Mokashi 14. January 2011 05:48

In the first part of this series we looked into Output Caching. In this part, we will see the options available with partial page caching. Just like output caching you can cache specific sections of a web page using partial page caching. This is achieved by caching user controls used for building the ASP.NET page.

User Controls are typically designed to be shared across multiple pages to enable reuse of their functionality. To achieve partial page caching, you can use the @OutputCache directive : using its default attributes will enable to cache the user control on a per page basis. By setting the Shared = “true” attribute, you can share the user controls among multiple pages. This leads to memory savings on the server, especially if your web site is made up of large number of pages (it always is, isn’t it ?:))

<%@ OutputCache Duration=”30” VaryByParam=”*” Shared=”true” %>

The above directive tells the .NET framework that a copy of the user control is cache and shared amongst all the pages using it for 30 seconds and to vary the cache by any and all parameters

Tags: , , , , ,

Coding

Installing WordPress on a IIS Windows box the easy way

by Swanand Mokashi 8. December 2010 01:42

So do you want to install WordPress on your Windows (server or otherwise) ? The usual steps are to :

  1. Install PHP
  2. Install MySql
  3. Install WordPress bits
  4. Pray all of the above works

You would ordinarily go to the various websites to get the PHP , MySql and WordPress bits. However there is a better way and surprisingly it is from Microsoft !! Microsoft “supports” WordPress – this is a no brainer for Microsoft really, WordPress is the most popular blog writing /Content Management system. It is written in PHP and uses MySql and is free and all of this works great on Windows. So it is just an additional revenue option for Microsoft in my humble opinion, to get the WordPress folks to use Windows Servers.

To that effect, Microsoft has been nice enough to create a “web installer” for WordPress. Just go to : http://www.microsoft.com/web/wordpress/ and click “Install Now” and it will go through all the above steps (may be not the “pray” step :)) and you will have a website that is running WordPress ! Easy, ain’t it? The best of both the world – open source software (WordPress, PHP, MySql) and nice easy and simple install package from Microsoft.

Tags: , ,

Coding

Brief about ASP.net Master Pages

by Jane Thomson 30. November 2010 19:04

As we all know, with the release of ASP.net 2.0, it has become quite easy to create uniform layout across almost all the pages on a website. Let us look at some brief of the ASP.net master pages here in this article.

 

In order to create uniform pages across the website, a user needs to create only one master page which can characterize the look, feel and typical behavior of all the pages across the website. After that, individual content pages can be created with the given look and feel with required content on the page. Thus, while user requests for the content page, ASP.net merges it with the master page to create a combine page of defined layout and content.

 

Just like master pages, there exists a feature called dynamic web template. However, it is advised to use master pages while using the ASP.net to give a consistent look across the website with the share content pages. And if a user is working with the HTML files, it is advisable to use the dynamic web templates.

 

Benefits of Using Master Pages

 

Let us now look at the benefits of using the master pages in the ASP.net files which can convince a user to use the master pages in website. Traditionally, it was defined to copy all the code from one page to another page in order to create uniform pages across the website but master page has overtaken this duty to make it quite simple for a user. The benefits include:

 

  1. Master page allows unifying the common functionality required in all the pages so user only has to update a single page.
  2. Master page allows to create only single set of controls which can be applied to the pages across the website.
  3. With this, it also provides such a model object through which user can modify the master page through the individual content page.

Tags: ,

Coding

Howto : Quickly align code in Visual Studio

by Swanand Mokashi 23. November 2010 20:07

I recently had a project where I had to copy paste code from bunch of other projects that we had worked on. As a results the code was really not aligned in terms of tab indentation. As we follow a company wide standard for the code alignment, this was going to be a problem. But Visual Studio came to the rescue. Simply select the code block that you want to indent properly and then press CTRL+K followed by CTRL+D. Voila! The code is now nicely indented.

Tags:

Coding

ASP.net Themes and Skins

by Jane Thomson 27. October 2010 00:04

ASP.net themes are made up with the different kind of elements which includes CSS, skins, images as well as few other sources. If not anything else, themes will at least contain skins in it. The themes of ASP.net shall be defined in the particular directory for the website or on the web browser. Let us look at the skins feature of the ASP.net themes.

Skins

A skin in the ASP.net is stored with the extension .skin as a file and the file contains the different kinds of property settings for the controls such as Label, Calendar, Textbox or Command button etc. Generally, the settings of the control skin are just like control markup but only contains the properties that a user wants to set in the theme.

As said earlier, the .skin file is created under theme folder. A skin file can contain more than one control skins for more than one control. Instead, you can also define the different skins in the different file or let’s say in a separate file as well.

There are two different types of control skins, named skins and default skins. Let us look at them in details here.

1.    Default skin is the one which is applied to all the same type of controls when the theme is applied to any particular page. If the skin does not have the SkinId property, the control skin becomes the default skin. For an example, if user creates the default skin for the calendar control, it applies to calendar control on all the pages where the theme is applied.

2.    In contrary to default skin, if the control skin has a SkinId property, it is known as the named skin. This skin type is not applied to all the controls. Instead, a user has to apply named skin to the control by changing the SkinID property of the control.

Tags:

Coding

Configure ASP.NET for Membership Provider

by Jane Thomson 6. October 2010 20:54

Configure ASP.NET for Membership Provider

In order to use the membership features of ASP.NET, it is required to configure the membership features in the machine. Here are the basic steps that to follow for the same:

1.    First of all specify the options of memberships as a part of website configuration. Please specify which membership provider shall be used for the website. The provider that is available by default stores the membership details into the SQL Server database. However, there are other membership providers to use like provider from the Windows Live Id. Let us look at how we can configure Membership provider for ASP.NET web application.

2.    ASP.NET membership can be configured with the element membership located in the web.config file for the web application. In fact, the membership is a sub-element of the system.web section. It is possible to enable the ASP.NET membership directly by editing the web.config file of the web application. Even a website administration tool can be used for the same that provided the wizard based interface to configure it. To configure the membership feature, user has to specify:

a.    The membership providers to use. It also includes the database to store the membership information.

b.    Password option like encryption and whether it’s feasible to support the password recovery based on the user information.

c.    Username and Passwords. If the web administration tool has been used, users can be directly created and managed. If not, user has to call membership functions to create as well as manage the users.

3.    There is another feature with the membership provider is to select the membership provider with defaltprovider characteristic of membership element. There is a machine configuration SQLMembership Provider instance with the name “AspNetSqlMembershipProvider” which works as a default provider if the default provider hasn’t been specified. The “AspNetSqlMembershipProvider” provider is connected with the aspnetdb database in the SQL Server of the local machine. However, a user has to set up the database which is used by “SqlMembershipProvider” before it can be used in the application.

 

Specifying the Default Provider


You specify the default membership provider using the defaultProvider attribute of the membership element. The machine configuration specifies a SqlMembershipProvider instance named "AspNetSqlMembershipProvider" that is identified as the default provider if you do not specify a default provider explicitly. The "AspNetSqlMembershipProvider" connects to the aspnetdb database in the local SQL Server.

Please refer to the code below in order to check the web.config file.

<configuration>

  <connectionStrings>

    <add name="MySqlConnection" connectionString="Data

      Source=MySqlServer;Initial Catalog=aspnetdb;Integrated

      Security=SSPI;" />

  </connectionStrings>

  <system.web>

    <authentication mode="Forms" >

      <forms loginUrl="login.aspx"

        name=".ASPXFORMSAUTH" />

    </authentication>

    <authorization>

      <deny users="?" />

    </authorization>

    <membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="15">

      <providers>

        <clear />

        <add

          name="SqlProvider"

          type="System.Web.Security.SqlMembershipProvider"

          connectionStringName="MySqlConnection"

          applicationName="MyApplication"

          enablePasswordRetrieval="false"

          enablePasswordReset="true"

          requiresQuestionAndAnswer="true"

          requiresUniqueEmail="true"

          passwordFormat="Hashed" />

      </providers>

    </membership>

  </system.web>

</configuration>

 

Tags:

Coding

ASP.NET Membership features with .net Framework 4

by Jane Thomson 6. October 2010 20:51

ASP.NET Membership features with .net Framework 4

Membership provider is a standalone feature in the ASP.NET to provide the authentication; it can easily be integrated with the role management functionality in order to provide the authorization servicing feature for the website. If needed, membership provider can also be integrated with the user profile provider in order to make available the application related customization for individual users.

The membership features can be used in order to authenticate the users either in the website or in the application built with ASP.NET. Generally, users can use membership features to provide the pages of log in such as to create a new log in or to request for the new password with forgot password page. Virtually, ASP.NET encapsulates all the required logic, prompts the users for the login details and validates the login credentials to allow the access to the membership area. In fact, default template for creating such pages includes most of these basic functionalities about login. Let’s say, if user has already created an application to use the authentication form. ASP.NET will by default display the authentication page if it is requested by the unauthenticated users.

If a user uses the login controls or project templates from the ASP.NET, membership provider to validate the user credentials will by default be used. If a user decides to use the customized login controls, it is necessary to use the validateuser method to validate the user credentials. After validating the user information, it can be stored such as encrypted cookie in user’s machine (if user’s machine allows doing so). The membership provider will automatically use this feature. However, if you are using the customized login controls, Forms Authentication control can be used to generate the cookies in order to store it into the user’s machine. The membership credentials can also provide the features to recover password with the recover password and reset password user controls.

Tags:

Coding

ASP.NET Caching – A Primer : Part 1 – Output Caching

by Swanand Mokashi 19. August 2010 07:40

Introduction

ASP.NET Caching has to be the one the most under utilized feature of ASP.NET . Caching is a process of storing frequently used data on the server to fulfill subsequent requests. The browser kind of does something similar for you on the client side, where it caches the webpage ,images etc to display them much faster the next time. ASP.NET caching does the same thing for you on the server side. The frequently used data is stored in the server memory and as you can imagine memory access is a lot faster than recreating the webpage from scratch. This leads to boosting the performance, scalability and availability of the website.

There are 3 different ways you can use ASP.NET caching : output caching,  partial page (UserControl) caching and programmatic caching. In this part, we will look at the output caching.

Output caching

Output caching enables to cache the entire dynamic HTTP page in the server memory and enable to retrieve it from the memory instead of recreating it. This means if you are using a master page for your site, for this particular webpage both the master page content and the content page content will be cached.

To achieve output caching is very simple : you need to add an OutputCache page directive at the top of an aspx page:

<% OutputCache Duration=”120” VaryByParam=”None” %>

The above example directive will store the webpage in cache for 120 seconds. The VaryByParam attribute determines which versions of the page are cached. The other available attributes are : VaryByHeader, VaryByControl, VaryByCustom and Location. Let us take a look at each of them

VaryByParam

You can specify which Querystring parameters will cause a new version to be cached:

<% OutputCache Duration=”120” VaryByParam=”productId;manufacturerId;” %>

The above example means store a separate version of the page in cache for each combination of productId and manufacturerId. Bear in mind the number of cached versions for this page will be (number of distinct productId * number of distinct manufacturerId). You can also specify “*” as the value for the VaryByParam and a separate version will be cached for any differences in the Querystring parameters. 

VaryByHeader

You can specify VaryByHeader to save a version for each variation in one of more headers that the browser sends.

<% OutputCache Duration=”120” VaryByHeader=”User-Agent” %>

The above example will store a version for each variation of the user-agent (i.e. browsers) in the cache.

VaryByControl

You can specify the VaryByControl attribute to cache the rendered output of the a UserControl

Location

Defines if page output can be cached on a proxy or downstream client. Often omitted, so that caching is performed in the most efficient way. However, it is a good idea to include Location="Any" where you do not actually need to control the location

VaryByCustom

As with most features in ASP.NET if the standard features do not work for you, you can use your own custom logic which offers the most flexibility. For example, say you want to take the OutputCache to vary by a value in a cookie or a session variable or whatever you can use VaryByCustom. There is a special method GetVaryByCustomString that can be added to the Global.asax.

The GetVaryByCustomString gets called each time a page is requested and the function returns a value. A different version of the page is cached for each unique value is returned. A good example is suppose you want to cache a fairly static page but if this page (or its master page) stores the referrer of the page as a session variable (say you have an ad campaign leading to this page, and you are tracking where your visitor came from). If you cache the page as is, then the session variable will always be empty (or the value will be the same as the first time the page was requested and put in cache). Now if you pass this variable to another page (or to another site via your external links) this will pose a problem. You can change the GetVaryByCustomString method to return the value of the session variable and that will take care of the issue.

The GetVaryByCustomString method has an input parameter arg passed in which is the same as what you type as the value for “VaryByCustom”. So in the above example if you use :

<% OutputCache Duration=”120” VaryByHeader=”Referrer” %>

The GetVaryByCustomString can be used as below :

public override string GetVaryByCustomString(HttpContext context, string arg)
    {
        switch (arg.ToLower())
        {
            case "referrer":
                //Get your session value and return it
                return "your_session_value";
                break;
            case "other":
                //You can have other pages that use the VaryByCustom attribute
                break;
        }
    }

Extending <OutputCache>

With ASP.NET 4.0 it is interesting that now you can extend the <OutputCache> directive to work off your own custom ways to cache. This way if you want to store your cache on the disc, cloud or database or anywhere else, you can do it.

In order to achieve this, you will need to create a custom cache provider class (inherited from System.Web.Caching.OutputCacheProvider) and override the Add(), Get(), Remove() and Set() methods.

The <outputCache> sub section under the <caching> section in the web.config has a new subelement <providers> and you can add your own output cache provider in there. Of course as with everything in ASP.NET, you can override this default cache provider by adding  the providerName attribute to the OutputCache directive for an individual page itself.

Hope this was a good primer on ASP.NET output caching. In the next part, we will see how to do partial page caching

Technorati Tags: ,,

Tags: , , , ,

Coding

Zip Code web services now available FREE!

by Swanand Mokashi 6. August 2010 02:05

We are happy to announce that our zip code webservices are now available for consumption, FREE of cost!


  • Zip Code Lookup Web Service : 
    Receive comprehensive information about a specified U.S. ZIP code

    This Web service returns information regarding the ZIP codes, associated area codes, ZIP code information by state and city, and latitude and longitude for defined geo locations. The output format can be consumed by any programming language including and not limited to C# or VB.NET ASP.NET, Java, PHP, Javascript, Pearl etc. 

    Access complete U.S ZIP code information for user defined ZIP code, city, and state. This Web service delivers comprehensive information regarding ZIP code, city, state, county, city type, latitude, longitude, time zone, elevation, day light savings flags, classification code, multiple county flag, and area codes. 
    ZIP code information can be delivered live via an XML-based Web service directly into any application, platform, product, or website.

    To access the web service click here

  •  Zip Code Distance Web Service
    Quickly access information to determine the distance between two defined U.S. ZIP Codes in miles or locate surrounding ZIP Codes in a specific mile radius for a given U.S. ZIP Code. The output format can be consumed by any programming language including and not limited to C# or VB.NET ASP.NET, Java, PHP, Javascript, Pearl etc. 

    This Web service delivers distance information for two specified U.S. ZIP Codes from central point to central point in miles. Easily access information to evaluate the straight line distance between the two locations. 
    Information regarding surrounding U.S ZIP Codes for a specific mile radius for a given U.S. ZIP Code is also available.

    To access the web service click here
If you need any more information,  please visit our "Contact Us" page

Tags:

Coding

::: | © Malaika Consultants LLC | :::

Malaika Consultants LLC

Malaika Consultants LLC is a custom software development consulting firm located in Cary (Raleigh Durham Research Triangle AKA RTP area ) North Carolina. We offer our expert consulting services in the Microsoft .NET and related technologies. Our mission is to partner with you and ensure the success of your project. We have a team in the USA that will help you with your Information Technology needs and we strive to be truly "Your Information Technology Angels"

We are offering 1 hour of free consulting -- ASP.NET, SQL Server, IIS, anything. Contact us to get your free consulting

Recent Comments

Comment RSS