Project party Photos

September 14, 2011 Leave a comment
Categories: Uncategorized

Alerting the user about Session expiry after idle-time in ASP.NET using javascript

Server side Timeout in ASP.NET

In ASP.NET the Server side session timeout to be 60 minutes rather than the default 20 minutes. We can do the following

  1. set in web.config
  2. Set session timeout to 60 minutes in IIS manager/Web site properties/ASP.NET configuration settings
  3. Set idle timeout to 60 minutes in application pool properties/performance.

If we use Forms authentication  it uses own value for timeout (30 min. by default). A forms authentication timeout will send the user to the login page with the session still active. This may look like the behavior your app gives when session times out making it easy to confuse one with the other.

 
<system.web>
<authentication mode="Forms">
           <forms timeout="50"/>
    </authentication>
<sessionState timeout="60"  />
</system.web>

Setting the forms timeout to something less than the session timeout can give the user a window in which to log back in without losing any session data.

How to intimate Session expiry by alerting the user

“When a user is on a page for longer than the required time he is timed out. There is a time-out value on the server that I need to capture and produce an alert box on the page. ”

just track it client-side like so:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title>Session Timeout Warning</title>
<script language="javascript" type="text/javascript">
    var maxInactiveInterval = 120;
function startCountdown() {
window.setTimeout(alertSessionTimeout, ((maxInactiveInterval-60) * 1000));
}

function alertSessionTimeout() {
alert("You're session is going to timeout in 1 minute.");
}
</script>
</head>
<body onload="startCountdown();"></body>
</html>

Here maxInactiveInterval holds the values for the Session to be expired in seconds. We have subtracted 60 seconds from the maxInactiveInterval, so the session will timeout before 1 min as the alert pops up.

Source: Session Expiry Thread

The SQL Server Code-Named “Denali” Community Technical Preview (CTP)

You can download this CTP at http://www.microsoft.com/downloads/en/details.aspx?FamilyID=6a04f16f-f6be-4f92-9c92-f7e5677d91f9.

To learn new features of the Denali.
Some of the new features are listed below.

  • SQL Server AlwaysOn.
  • T-SQL Enhancements.
  • Changed Startup Option.
  • Availability Groups(HADR).
  • Contained Databases.
  • Sequence.
  • Fulltext Search Enhancement.
  • New Collation Support.
  • Data Integration Management.
  • BI Enhancement.
  • Juneau.
  • Analytic Enhancement.
  • IT Administration.
  • Column  Based Query Accelerator.
  • Ad-Hoc Query Paging.
  • Code Snippets Manager.
  • Task List.
  • Zoom or Magnify.
  • High Availability and Disaster Recovery.
  • SSIS Enhancements.
  • Spatial data Type Enhancement.
  • Multi Subnet Fail-over Clustering.
  • Migration and Deployment.
  • Beyond Relational.
  • Security Enhancement.
  • Metadata Discovery.
  • Extended Order By Clause Functionality.
  • FileStream Enhancement.
  • Multi Monitor.
  • Replication Enhancement.
  • Service Broker.
  • Error Handling Enhancement.
  • Installation Enhancement.

You can find What’s new of  “Denali” here, http://msdn.microsoft.com/en-us/library/bb500435(v=sql.110).aspx.

Microsoft SQL Server Code-Named “Denali”, Community Technology Preview 3 (CTP 3) introduces 14 new built-in functions. These functions ease the path of migration for information workers by emulating functionality that is found in the expression languages of many desktop applications. However these functions will also be useful to experienced users of SQL Server.

The new functions are:

Conversion functions

Date and time functions

Logical functions

String functions

In addition to the 14 new functions, one existing function has been changed. The existing LOG (Transact-SQL) function now has an optional second base parameter.

OVER Clause Support Enhanced

The OVER clause has been extended to support window functions. Window functions perform a calculation across a set of rows that are in some relationship to the current row. For example, you can use the ROWS or RANGE clause over a set of rows to calculate a moving average or cumulative total. For more information, see OVER Clause (Transact-SQL).

In addition, ordering rows within a partition is now supported in the aggregate functions that allow the OVER clause to be specified.

The above said enhancements are subject to the Development alone. For more details Microsoft  Denali Enhancements

Exception : Activation error occured while trying to get instance of type___________,””

Activation error occured while trying to get instance of type___________,””

___________ – Refers to the class/object we are instantiate.

eg: Activation error occured while trying to get instance of type Database, key “DBName”

This means the connection to the Database is having some problem. Either Database name wrong or connection string wrong or wrong usage.

<dataConfiguration defaultDatabase=”con1″ />
<connectionStrings>
<add name=”con1″ connectionString=”Data Source=server1;Initial Catalog=dbName1;User Id=Username1;Password=password1;”
providerName=”System.Data.SqlClient

” />
<add name=”con2″ connectionString=”Data Source=Server2;Initial Catalog=dbName2;User Id=Username2;Password=password2;”
providerName=”System.Data.SqlClient” />
</connectionStrings>

Database myDB=EnterpriseLibraryContainer.Current.GetInstance<Database>(); –> works fine for the default database (con1)

Database myDB=EnterpriseLibraryContainer.Current.GetInstance<Database>(“con2”); –> Error message, see below

Activation error occured while trying to get instance of type Database, key “con2”

 

Rolling Flat File Trace Listener

August 4, 2011 2 comments

Overview

The Enterprise Library Logging Application Block simplifies the implementation of common logging functions. Developers can use the Logging Block to write information to a variety of locations:

  • The event log
  • An e-mail message
  • A database
  • A message queue
  • A text file
  • A WMI event
  • Custom locations using application block extension points

This article describes the RollingFileTraceListener extension of the Logging block of version 5.0 of the Microsoft Enterprise Library.  This is a custom trace listener that can be added into the Enterprise Library Logging block like the standard trace listeners that are included. The FlatFileTraceListener shipped with EntLib 5.0 may not be adequate for enterprise systems since log files by default will continue to grow unchecked.  This new trace listener provides support for rolling over log files based on age of the log file or file size.

Step 1 — Setting up the Environment

To meet our requirements we only need the following assemblies.

  • Microsoft.Practices.EnterpriseLibrary.Common.dll
  • Microsoft.Practices.EnterpriseLibrary.Logging.dll

Step 2 — Configuring your applications config file

Source Schema for the Logging Application Block (loggingConfiguration)

<configSections>
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null" />
</configSections>

Table1: Properties to be configured for this Rolling Flat File Trace Listener under the loggingConfiguration

Property Description
Filters All log entries are passed through filters, you can use them to block the logging based on a category or priority etc. We won’t be using this for our example.
Category Sources You can have your own category definition or use the ones provided by default like Logging Errors & Warnings, Unprocessed category or All Events.
Trace Listeners This is the main guy who does the listening and you can define the Trace Listener of your choice. Since we are writing to event logs and text, we will use the “Formatted Event Log Trace Listener” and the “Rolling Flat File Trace Listener”
Formatters These define the kind of formatting you need for your log entry, you get to choose between Binary, Custom and Text. We will use the Text formatter.
Inside this logging Configuration schema we are going to configure all the above properties
<loggingConfiguration tracingEnabled="true" defaultCategory="General" >

 

Category Sources:

<categorySources>
      <add switchValue="All" name="General">
        <listeners>
          <add name="Rolling Flat File Trace Listener" />
        </listeners>
      </add>
</categorySources>
<specialSources>
      <allEvents switchValue="All" name="All Events" />
      <notProcessed switchValue="All" name="Unprocessed Category" />
      <errors switchValue="All" name="Logging Errors &amp; Warnings">
        <listeners>
          <add name="Rolling Flat File Trace Listener" />
        </listeners>
      </errors>
</specialSources>

Trace Listeners

<listeners>
      <add name="Event Log Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                source="Enterprise Library Logging" formatter="Text Formatter"
                log="" machineName="." traceOutputOptions="None" />
      <add name="Rolling Flat File Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                fileName="C:\MyLogFile.log" footer="" header="" rollInterval="Hour"
                traceOutputOptions="None" formatter="Text Formatter" rollSizeKB="10000" timeStampPattern="yyyy-MM-dd" rollFileExistsBehavior="Increment"/>  
</listeners>

Formatters

<formatters>
      <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
     template "Timestamp: {timestamp}{newline}Message: {message}{newline}Category: {category}{newline}Priority: {priority}{newline}EventId: {eventid}{newline}Severity: {severity}{newline}Title:{title}{newline}Machine: {machine}{newline}Application Domain: {appDomain}{newline}Process Id: {processId}{newline}Process Name: {processName}"  name="Text Formatter" />
</formatters>

 

Source Schema for the Exception handling Block (exceptionHandling)

<configSections>
    <section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"/>
  </configSections>

Table2: Properties to be configured for this Rolling Flat File Trace Listener under the exceptionHandling

Property Description
Exception Policies The Exception Handling Application Block lets you associate exception types with named policies. Policies specify the exception handlers that execute when the application block processes a particular exception type

Inside this <exceptionHandling> Configuration schema we are going to configure the above property.

<exceptionPolicies>
   <add name="Log Only Policy">
        <exceptionTypes>
          <add name="Exception" type="System.Exception, mscorlib" postHandlingAction="None">
            <exceptionHandlers>
              <add logCategory="Default Category" eventId="100" severity="Error" title="Quick Start Application Exception" priority="0" formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling" name="Logging Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging"/>
            </exceptionHandlers>
          </add>
        </exceptionTypes>
      </add>
    </exceptionPolicies>

 

Rolling Flat File Trace Listener

The below lists the properties that appear when you add a Rolling Flat File Trace Listener. This trace listener allows you to control the size and age of a log file.

Table 3: Rolling Flat File Trace Listener Properties

Property Description
Name This is the name of the trace listener. This is required.
FileName This is the name of the rolling flat file. This is required.
Footer Additional information contained in the file footer. The default is —————————————-. This is optional.
Formatter The formatter to use with this trace listener. Select from the drop-down list. The default is none. This is optional.
Header Additional information contained in the file header. The default is —————————————-. This is optional.
RollFileExistsBehavior This property determines what occurs to an existing file when it rolls over. If you select Overwrite, then the existing file is overwritten. If you select Increment, the application block creates a new file and names it by incrementing the timestamp.
RollInterval This property determines when the log file rolls over. You can select none (the default), minute, hour, day, month, or year. This is optional.
RollSizeKB This is the maximum size the file can reach, in Kilobytes, before it rolls over. This is optional.
TimeStampPattern This is the date/time format that is appended to the new filename as mentioned below. This is required.
TraceOutputOptions Trace listeners use this option to determine which options, or elements, should be included in the trace output. Possible values are: CallStack, DateTime, LogicalOperationStack, None, ProcessId, ThreadId, and Timestamp. The default isNone. For an explanation of these values, see the TraceOutputOptions Values table. This is optional.

Remarks

You can control either or both the size of the file and its age. For example, if you specify in configuration a RollSizeKB value of 5KB and aRollInterval value of Day, the file rolls when its size exceeds 5KB and it also rolls at the end of the day.

If you select Increment for the RoleFileExistsBehavior, the application block creates a new file when the existing file rolls over. The file’s name includes the current timestamp. If a file with this name already exists, the application block adds an integer to the end of the timestamp and increments it until it cannot find a file with that name. For example, assume there is a file named mylog2007-01-1.8.log and the file rolls over while that timestamp is still valid. The application block will then look for a file named mylog2007-01-18.1.log. If no such file exists, it will use that file name for the new file. If that file also exists, it will then attempt to locate the log with the next sequence numbermylog2007-01-18.2.log.

If you select Overwrite for the RoleFileExistsBehavior, the application block creates a new file when the current file rolls over. The name of the file includes the current timestamp. If a file with that name already exists, the application block overwrites the file. If, for some reason, it cannot overwrite the file, it will generate a name according to the same process that is used with the Increment value.

Relative path names resolve to a location that is relative to the AppDomain.CurrentDomain.BaseDirectory directory.

Step 3 — Code Sample to write to Event Logs, Debug and Tracing

ExceptionPolicy.HandleException(ex, “Log Only Policy”);

And here is how the log to Text file looks like

—————————————-
Timestamp: 1/5/2009 3:03:41 AM

Message: This is being written to text file
Category: DebugCategory, Trace
Priority: 2
EventId: 2000
Severity: Information
Title:My method
Machine: <<MYMACHINENAME>>
Application Domain: MyLoggerTest.exe
Process Id: 2288
Process Name: D:\projects\MyLoggerTest\MyLoggerTest\bin\Release\MyLoggerTest.exe
—————————————-

HTML5 Resources

Categories: ASP.NET Tags: ,

Custom session state management

ASP.NET includes several options that help you preserve data on both a per-page basis and an application-wide basis. These features are as follows:

  • View state
  • Control state
  • Hidden fields
  • Cookies
  • Query strings
  • Application state
  • Session state
  • Profile Properties

View state, control state, hidden fields, cookies, and query strings all involve storing data on the client in various ways. However, application state, session state, and profile properties all store data in memory on the server. Each option has distinct advantages and disadvantages, depending on the scenario.

We are going to concentrate on Session state:

In this custom session state management we will create one class named “ApplicationSession” with one member(Property) with return type as the same Class which returns object of the class. We are creating the object of the class and placing it in session.  Which means the members(Property) which are created inside the class will also be acting as a session variable. 

using System.Web.UI.WebControls;

/// Summary description for ApplicationSession

public class ApplicationSession
{
#region Session Property
/// Gets the current session.
public static ApplicationSession Current
{
get
{
ApplicationSession session =
(ApplicationSession)HttpContext.Current.Session[Constants.Session];
if (session == null)//if session is null create session
{
session = new ApplicationSession();
HttpContext.Current.Session[Constants.Session] = session;
}
return session;
}
}
#endregion
#region Session variable with Properties
public string LoginName { get; set; }

#endregion
}
Here LoginName is the Session variable which stores the LoginName of the User sign-in into the application.
Using this we can reduce the coding for the session objects.

HTML5 Boilerplate

What’s in HTML5 Boilerplate?

If you select the documented or stripped options you’ll get a .zip file that contains an HTML5 skeleton to help jumpstart your Web development. Here’s what the site structure looks like. Looking through the folders you’ll see that they contain CSS, JavaScript and HTML files as well as favicon.ico, crossdomain.xml for Flash and Silverlight, a 404.html page, robots.txt for search engines and QUnit testing functionality.

 

image

 Source : Dan Wahlin’s Weblog

Get started with HTML5

HTML5

HTML5

HTML5 improves interoperability and reduces development costs by making precise rules on how to handle all HTML elements, and how to recover from errors.

Some of the new features in HTML5 are functions for embedding audio, video, graphics, client-side data storage, and interactive documents. HTML5 also contains new elements like <:NAV>, <:HEADER>, <:FOOTER>, and <:FIGURE>.

HTML5 is the next major update to the W3C HTML specification providing a standard structure for presenting content on the web. The W3C HTML5 specification adds new features like graphical support through SVG and Canvas, multimedia support like inline video and audio, as well as new APIs to make it easier for developers to create rich, interactive web applications. Like CSS2.1, CSS3 gives designers and developers the ability to apply presentation semantics to their HTML pages

What is the SSS in HTML5?

This will be the first of a series of blog posts to help someone new to HTML5 development.  The first item to address is:  What is meant by the term HTML5?  I like to think of it as “Triple S” or SSS.

  • Source
  • Style
  • Script

Source refers to the HTML markup itself, the tags.

Style refers to the inline styles and/or modules from CSS3.

Script refers to the development aspect of HTML5 with Javascript.

Reference : HTML5


HTML5 New features are categorized into 3 based on its behaviour

  1. HTML5 New Tags
  2. HTML5 New Attributes
  3. HTML5 New Events

      Events are again categorized into

  • Window Events
  • Form Events
  • Mouse Events
  • Media Events                  

HTML5 A New Doctype

To start using HTML5 you’ll need to use the new HTML5 doctype and all you need is the following snippet of code. Simply place this on the first line of your HTML document and you’re ready to start using HTML5. its short, simple and doesn’t take up unnecessary HTTP space.

<!DOCTYPE html>

Don’t think about the other settings for Doctype. Forget it and move on.

The HEAD section

The head section of an HTML5 document will be simple and the meta tag for the character set has been simplified . 

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Page Title</title>
<!-- meta tags -->
<meta name="keywords" content="">
<meta name="description" content="">
<!-- stylesheets -->
<link rel="stylesheet" href="css/reset.css" type="text/css">
<link rel="stylesheet" href="css/common.css" type="text/css">
<!-- javascript -->
<script src="js/jquery-1.4.1.vsjdoc..js"></script><script src="js/jquery-1.4.1.js"></script>
<script src="js/jquery-1.4.1.min.js"></script>
<!--conditional comments -->
<!--[if IE]>
<script src="js/html5.js"></script>
<![endif]-->
</head>

Script

We don’t need a full script tag anymore, the default type is Javascript.

Style

The different about the style tag is “No type”. The type defaults to CSS.  You have to set the HTML5 elements to display:block or they will render as inline (at least for now).

The BODY section Semantic Structure

Before HTML5 the HTML Code can be of the below markup for defining header, footer etc.,

<html>
    <body>
        <div id="header">
            <h1><a href="/">Office Name</a></h1>
        </div>
        <div id="navigation">
            <ul>
                <li>Clients</li>
                <li>Employees</li>
                ...
            </ul>
        </div>
        <div id="content">
            <h1>Welcome</h1>
            <div class="photo"><img src="..." alt="..." /></div>
            <p>...</p>
        </div>
        <div id="footer">
            <p>...</p>
        </div>
    </body>
</html>
HTML5 Semantic Structure

HTML5 Semantic Structure

HTML5 builds on the above Structure, which includes some new tags to do this and reducing the markup code. The HTML uses the HEADER and NAV elements to contain these elements. The HEADER element can be used to markup the header for the page but could also be used to markup the headers within the content. 

 

The NAV element can also be styled using CSS independently of any other elements.

 
HTML5 builds on that same very structure but now instead of having a bunch of div’s to contain your content you have these tags to better explain what you’re marking up.
  • <header>
  • <nav>
  • <section>
  • <article>
  • <aside>
  • <footer>

The new structure would look something like this:

 
<html>
    <body>
        <header>
            <h1><a href=”/”>Office Name</a></h1>
        </header>
        <nav>
            <ul>
                <li>Clients</li>
                <li>Employees</li>
            </ul>
        </nav>
        <section>
            <h1>Welcome</h1>
            <aside><img src=”…” alt=”…” /></aside>
            <article>
                <p>…</p>
            </article>
        </section>
        <footer>
            <p>…</p>
        </footer>
    </body>
</html>

New Elements in HTML5

HTML5 introduces quite a few new elements. Here’s the complete list with brief descriptions (source: w3schools): 

  • <article> Defines external content 
  • <aside> Defines some content aside from the article it is placed in 
  • <audio> Defines sound, such as music or other audio streams 
  • <canvas> Defines graphic, such as graphs or other images 
  • <command> Defines a command button, like a radiobutton, a checkbox, or a button 
  • <datagrid> Defines a list of selectable data. The datagrid is displayed as a tree-list 
  • <datalist> Defines a list of selectable data. Use this element together with the input element, to make a dropdown list for the input’s value 
  • <datatemplate> Defines a container for data template. This element must have child elements to define a template: <rule> elements 
  • <details> Defines details of an element, which the user can see, and click to hide 
  • <dialog> Defines a dialog, such as a conversation 
  • Defines embedded content, such as a plug-in 
  • <event-source> Defines a source for events sent by a server 
  • <figure> Used to group some elements
  • <footer> Defines the footer of a section or document. Typically contains the name of the author, the date the document was written and/or contact information 
  • <header> Defines the header of a section or document 
  • <mark> Defines marked text. Use the <mark> tag if you want to highlight parts of your text 
  • <meter> Defines a measurement. Used only for measurements with a known minimum and maximum value 
  • <nav> Defines a section of  navigation links 
  • <nest> Defines a nestingpoint in a datatemplate for child elements. Used together with the elements <datatemplate> and <rule> 
  • <output> Defines different types of output, such as output written by a script 
  • <progress> Defines work-in-progress. Use the progress element to display the progress of a time consuming function in JavaScript 
  • <rule> Defines the rules for updating a datatemplate. Used together with the elements <datatemplate> and <nest> 
  • <section> Defines sections in a document. Such as chapters, headers, footers, or any other sections of the document 
  • <source> Defines media resources for media elements, such as <video> and <audio> 
  • <time> Defines a time or a date, or both 
  • <video> Defines video, such as a movie clip or other video streams

Summary

This article briefly introduced the new elements and its features included in HTML5. HTML5 is not going away so get your coding hat on and get to work!

 

 
 
 
 
 
 
 
 
 
 
 
Categories: ASP.NET Tags:

CSS Sites

Categories: CSS Tags: , ,