Posts Tagged ‘.NET’

Creating a custom section using Umbraco

Saturday, August 14th, 2010

Umbraco is an open source CMS (content management system) based on Microsoft ASP.NET.

The unique features  that distinguishes Umbraco are :

-It is a CMS that can support any modern browser

-It allows editing  on  Microsoft Word.

-It is a source where designers can create accessible and valid xhtml without using  mark- up conventions.

- Developer 's can integrate any sort of control based on .NET platform.

Umbraco's administration area is divided into different sections. In order to add bespoke functionality to the Umbraco platform ,a custom section has to be built.

For Instance,  Let us create a sample 'Invitation sending ' functionality in Umbraco platform.

Steps to be followed :

  • Let the custom section  be  named  “Invitation”
  • Add the information about the custom section to Umbraco database, in three specific tables.
  • First , add  entry on to the umbracoApp table where  the created sections are stored

  • Next  add an entry to the umbracoAppTree table. This will display  custom section “Invitation” as the top level item on the tree.

  • Give  administrator  the permission to access the Custom section, so  add  entry to the umbracoUser2app table as  shown.

  • Next we have to create an icon which defines  the custom section. The  image  can be created using Photoshop that fits into the Umbraco Administration panel. Next place the image under the umbraco\images\tray\ folder. Make sure that the image name is same as defined in umbracoApp table.
  • Since Umbraco supports several languages, we need to register  entry to the languages file. located under umbraco\config\lang folder. Please add the following  to  en.xml file.

  • Next  step is creating a  web application called MyCustomAssembly .
  • For this create files  ,sendInvitation.aspx and listInvitation.aspx . Here we  add the required logic to implement the functionality. Place both the files in a new folder “Invitation” , created under the Umbraco folder.
  • Next create a class named “loadInvitation.cs” which contains the logic to list the custom tree node structure and respective actions and the coding  for mat  for this  is:

  • Now add the created custom dll on to the bin folder under Umbraco root installation .
  • Desired  Custom Section is thus created & the screen image will appear as shown.

After following the above given steps,  refresh the Umbraco section page . You can see the Custom section called “Invitation” displayed  and further clicking  on  'Invitation ' section , you can see a tree structure on the left pane displaying the 'send invitation ' and 'list invitation' child nodes.

We  will be  back with  detailed post on Umbraco customization  from developer's  perspective  in  future.

    Sessions never Die

    Monday, May 3rd, 2010


    A session is the time period for which a user interacts with a web application. Session objects can be used to store data which is specific to a particular user and these session objects can be accessed from anywhere within the application. A session is valid only for a particular length of time specified as its Timeout. On each request, if the sliding expiration is enabled (which is set by default in visual studio) the timeout period is reset to current time plus the timeout value. Default timeout period in ASP.Net is 20 minutes. We can manually alter the timeout period to the desired value by setting the timeout parameter in web.config. The maximum value possible is 24 hours.

    Sometimes, the client may require increasing the timeout period or even avoiding the session from expiring while the user is logged in. This article briefly describes the various methods used to extend the expiration time of the session.

    1.       Setting the timeout parameter in the web.config file

          The easiest method to set the timeout period is by setting it in the web.config file as shown below.


    <sessionState cookieless="false" mode="InProc" timeout="90"> </sessionState>

     

    The timeout=”90” implies that the session will be alive even if the user remains idle for 90 minutes.

    But there is a problem associated with this. As you all know, the session objects are stored in the server memory. Setting the timeout value to anything greater than one hour will result in excessive memory being held on the server, as IIS holds the entire session memory for the duration of each session, in turn holding the sessions of thousands of users in heavily trafficked web sites, which in turn affects the performance of the application.

    2.       By using Page Method

           The best method to refresh the session state is by making a request to the server. In this method we are making an Ajax request to the server at regular intervals of time, which in turn refreshes the session timeout, provided that the sliding expiration is enabled.

            We can use a JavaScript function to call the page method at fixed intervals of time. 

    aspx:

      <script type="text/javascript">

      

       window.setInterval("RefreshSession()",300000);

       

       function RefreshSession()

       {

           PageMethods.RefreshSessionState();

       }

      </script>

    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"> </asp:ScriptManager>

    aspx.cs:

     

    [WebMethod]

    public static void RefreshSessionState()

    {

       // do nothing

    }

    Here, we are calling the server method ‘RefreshSessionState’ at a fixed interval of time (5 minutes). So in every 5 minutes, the timeout period is being reset to current time plus the timeout value resulting in the session being alive forever.

    This method is much effective if the need is to maintain the session particularly for one or two pages. If the requirement is to keep the session alive for the whole application, we need to add this code in each and every page of the application which is very time consuming. Instead, we can add the code in the masterpage. But including the scriptmanager in the masterpage will load the application which is not a good programming practice.

     

    Meta refresh And Postback

    This method also creates a request (postback) to the server in order to refresh the session state. This can be done using a meta-refresh tag placed inside an Iframe whose width and height is set to zero.

     In the master page, we have to include the Iframe as,

    <iframe ID="SessionFrame" src="RefreshSession.aspx" frameBorder="0" width="0" height="0" runat="server"></iframe>

    Now add a new page named RefreshSession.aspx and in the head section of the page, include the following code,

    <meta id="MetaRefresh" http-equiv="refresh" content="7200;url= RefreshSession.aspx" runat="server" />

    Here we have set the content value to 7200 seconds, which is equal to 2 hours. However, we will be setting this value ourselves in the Page_Load for this page, so this value can be ignored.

    Add the following code to the Page_Load of RefreshSession.aspx.cs:

     

    if (Session[“User”] != null)

    {               

       // Refresh this page 60 seconds before session timeout,

       //effectively resetting the session timeout counter.

     MetaRefresh.Attributes["content"] =

    Convert.ToString((Session.Timeout * 60) – 60) +

     

                        ";url=RefreshSession.aspx?q=" + DateTime.Now.Ticks;

    }

    Here we are adding a varying query string parameter at the end of the target URL (RefreshSession.aspx). Otherwise browsers will cache the RefreshSession.aspx page and the session never gets refreshed. So we are adding random query string values to avoid the browser caching of that page. The auto-refresh of the Iframe will occur 1 minute prior to the expiration of the session.

    The next thing we need to take care of is to set the session timeout parameter in the web.config file to any value which is less than the IIS’s timeout value as discussed earlier. A value between 10 and 40 minutes will do the job perfectly.

    The advantage of the above two methods over the conventional web.config session timeout method is that we can keep a session alive forever as long as the user’s browser window is open. Also as soon as the user closes the browser, the session will expire hence resulting in quickly freeing up the server memory which holds the session.

    By .NET Team, Software Associates

      Visual studio 2010, .NET framework 4, Silverlight 4 released – Software Associates

      Wednesday, April 14th, 2010

      Web developers around the world have something new to look into. Microsoft Corporation has announced the general availability of Visual Studio 2010, .NET Framework 4 and Silverlight 4 in the second week of April 2010.  These  technologies in combination can take advantage of new and existing devises and emerging platforms.

      This web application framework is an upgrade to the rich internet plug-in platform that integrates multimedia, animation, graphics and interactivity into single runtime environment. Since its first release in 2007, the framework has been enhanced to be compatible to the emerging technologies.

       The current version of the Silverlight, will be released to web on 15th April 2010. The feedback are hence yet to be waited for.

      Some of the highlighted features included are:

      • Google Chrome compatibility 
      •  Extended out-of-browser capabilities. It provides XAP signing and verification for application integrity as well as custom window chrome for application presentation flexibility.
      • Leveraged for application development on Windows Phone 7 platform.
      • Printing and control capabilities
      • Pre-written control for quickly build rich, interactive applications.
      • Web cam and microphone support
      • Browser support for rendering HTML inside Silverlight
      • Content protection for H.264 and support for playing offline DRM protected media.

       

      The new release is expected to offer powerful business application capabilities in simpler and efficient ways.

       

      Visual Studio 2010

      We have already talked about Visual Studio 2010 in detail, we would be covering it here in brief. This version was developed to reduce clutter and complexity of the previous versions.

       For the Visual Studio developers

      • The new editor use Windows Presentation Foundation which supports multiple monitor and multiple document windows.
      • Integrated access of Sharepoint functionality into Visual Studio IDE. 
      • Windows Azure tools to quickly develop, debug, test and deploy cloud applications from within the familiar Visual Studio environment.
      • Built-support for ASP.NET Model-View-Controller to separately update the appearance and core business logic of applications.
      • Integrated Phone Design Surface of Visual Studio for mobile application developments.
      • Enhanced testing and developing features.
      • Most of the common tasks have been automated
      • IntelliTrace .tool to trace non reproducible bugs by recording the application's execution history using
      • Includes Multi-paradigm programming language ML-variant F# , M-the textual modeling language, and Quadrant, the visual model designer
      • Quicksearch features
      • Windows 7 Multitouch and ribbon interfaces will increase the flexibility for the end users.

       

      Visual Studio 2010 comes with .NET framework 4 and supports application development targeting Windows 7. 

       

      .NET Framework 4

       

      .NET Framework 4 has come with additional support for industry standards. It requires operating systems such as Windows 7; Windows Server editions, Windows Vista; Windows XP etc

       A few of the features are:

      • More language choice
      • Support for high-performance middle-tier applications including parallel programming, and side-by-side installation with .NET Framework 3.5.
      • It includes Oslo modeling platform, along with the M programming language
      • Faster deployments

       More set of enhancements such as Dublin are been awaited.  

      We at Software Associates are eagerly awaiting the release!!

        By .NET Team, Software Associates

        Using profile property in ASP.NET

        Thursday, March 11th, 2010

        When using the Membership API in the .NET Framework, only the core properties related to a user account is stored.  To add additional properties to a user’s account, we need to customize the database to store the additional information. But a much simpler work around is available by using the

        Profile properties are used in applications where you need to store and use information specific to each user. It can be used when you need to present the user with a personalized webpage according to his country, preferences or other factors. You can store this information in the session, but this will lead to the user preferences being lost when the session times out or if the user logs out of the system. By using profile features we can store user specific information in a persistent way because each time a user logs in, additional information regarding the user is stored to the database. So the next time a user visits the site, this information can be fetched from the database as and when needed.

        In order to be able to use the profile properties, you need to configure a profile provider. The default provider available in the .NET framework is the SqlProfileProvider. 

        To operate the profile properties you need to create a SQL database to hold the data. You can create the database by running the Aspnet_regsql.exe command. You can find it here- C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regsql.exe.

        Here we can select a particular database to apply the profile properties. If we do not specify a particular database, a new database is created with the name ‘aspnetdb’

        To start using the profile properties in your web application you need to configure it in the web.config as follows.

        For each property, you can specify the name, data type, and how the data should be serialized. There are four serialization options:

        • ProviderSpecific (by default) – the profile provider is left to determine how to serialize the property value
        • The property value is converted to a string.
        • The property value is converted to an XML representation.
        • The property value is converted to a binary representation.

        Eg:-

        <configuration>
               <system.web>
                  <profile>
                     <properties>
                        <add name="Gender" type="System.Boolean" allowAnonymous="true"/>
                     </properties>
                  </profile>
               </system.web>
        </configuration>

        The element adds a Profile property named 'Gender' of type Boolean and serialized as chosen by the Profile provider. There are additional attributes that can be included in the element, such as defaultValue and readOnly, among others. You can also group properties as follows,

        Here two profile properties, Gender and MaritalStatus are grouped under UserDetails.

        <configuration>
               <system.web>
                  <profile>
                     <properties>
                        <group name="UserDetails">
                            <add name="Gender" type="System.Boolean"/>
                            <add name="MaritalStatus" type="System.String"/>
                        </group>
                     </properties>
                  </profile>
               </system.web>
        </configuration>

        Using Profile Properties in Code

        Once the Profile properties are defined, the ASP.NET engine automatically creates a ProfileCommon class that has properties that map to the properties defined in the Web.config. The custom ProfileCommon class is accessible in the code portion of an ASP.NET page through the HttpContext object’s Profile property.

        So for reading the Profile property set for the currently logged in user, say Gender, just use Profile.Gender. In fact, as soon as you type in and hit period, IntelliSense brings up the various properties.> For accessing a grouped property, type in the Profile name followed by the group name and the property, for example, Profile.UserDetails.MaritalStatus

        We can assign values to profile properties as,

        Profile.Gender = true;
        Profile.UserDetails.MaritalStatus = "Single";

        We can read values stored to profile properties as,

        bool gender = Profile.Gender;
        string maritalStatus = Profile.UserDetails.MaritalStatus;

        The SqlProfileProvider stores the Profile property values in the table in a SQL Server database. It automatically handles all of the serialization and deserialization work and all that is left for us to do is programmatically read from and write to the user's Profile data through the profile property

        By .NET Team, Software Associates

          Caching – A performance booster

          Tuesday, June 16th, 2009

          For years, technology products have used caching to bring high performance. Simply put a cache becomes most of the time, the final solution to increase the performance of a data request. Page and DNS Caching are now critical for all operations in the wired space. Recently caching became really popular for Database access management.

          Caching provides two key benefits for Internet users

          • Reduce latency – Though the requests satisfy from the cache, which is closer to the client, caching reduces the overall network latency and returns much faster pages to the browsers.
          • Reduce network traffic – Caching, for some extent reduces the network bandwidth requirement as much as 35 percentage. Because most of the requests gets fulfilled locally and can avoid the transfer over expensive WAN. This saves money if the host charges for the traffic.

          Web Caching

          A web Cache lies between one or more web servers and clients, which analyzes the requests comes, save copies (HTML, images and files) and waits for another request for the same and responds with the saved copies instead of asking for the original to server it again. While Caching used to store Database information, retrieving the information from database takes time. With careful optimization we can reduce the time and lessen the burden imposed on database to a certain extent, but sure we can never eliminate it. In the case of page caching, cache server monitors which page object are frequently requested and store those objects locally. When these objects are later requested, the cache delivers it from local storage rather than forwarding the requests on to the original server.

          Web Caching can mainly divided into

          To know more about Web Caching and Data Caching click the above links. You can directly write to us for any queries.