ASP.NET 4.0 Hosting & ASP.NET 4.5 Hosting BLOG

BLOG about ASP.NET 4.5 Hosting, ASP.NET 4.0 Hosting and .NET 4.5 Framework and its Capabilities

ASP.NET 4.5 Hosting :: Model Binding Feature in ASP.NET 4.5

clock November 28, 2011 10:05 by author Administrator

The Good News - In ASP.NET 4.5, we can adopt an approach using which the Model can be directly bound with the DataBound controls and CRUD and pagination operations can be implemented very effectively. It incorporates concepts from the ObjectDataSource control and from model binding in ASP.NET MVC. We will see this shortly. ASP.NET 4.5 is based upon .NET 4.5 and it gets installed once you install Visual Studio 2011 preview. 

Note: If you want to install Visual Studio 2011 preview, you can also use the Windows 8 Developer preview.

In this article I will be explaining a new ASP.NET 4.5 exciting feature called ‘Model Binding with Web Forms’. Up to previous versions, webforms for data-binding used to make use of the ‘Eval’ method. During runtime, calls to Eval makes use of reflection against the currently bound data object and reads value of the member with the given name in Eval method. (Read Why Eval is Evil). Once this value is read the result is displayed in HTML. Although this is easiest way of data-binding, it has limitations like checking the binding name during compilation time etc.

Update: Also check out the second part of this article ASP.NET 4.5: Filtering using Model Binding in ASP.NET Web Forms

In ASP.NET 4.5 the Model Binding has improved. We will be going through the complete model binding feature using the following steps:

- Model binding with Web Forms.
- Value Providers.
- Filtering.
- Performing Update Operations.

For this article I am using Sql Server 2008 R2 and a ‘Company’ database, with following Tables:

Department - DeptNo (int) Primary Key, Dname (varchar(50)),Location (varchar(50)).
Employee - EmpNo (int) Primary Key, EmpName (varchar(50)),Salary (int), DeptNo(int) Forwign Key.

Let’s get started.

Step 1: Open Visual Studio 2011 Developer Preview and create a new Web Application, make sure that the Framework version you select is .NET 4.5. Call this application ‘ASPNET45_ModelBinding’.

Step 2: In this project, add new folders and name them as Model and Department. In the Department folder, add two Web Forms (with master page). Name them as ‘Departments.aspx’ and ‘DepartmentDetails.aspx’.

Step 3: In the Model folder, add a new ADO.NET entity data model and name it as ‘CompanyEDMX.edmx’. In the Wizard, select Company Database and select Department and Employee table. After the completion of wizard, the below result will be displayed:


Step 4: Open the Departments.aspx in the ‘Source’ view and add the Repeater control in it with the Department model bound to it as below.

The above code shows some modified databound features for DataBound controls in ASP.NET 4.5. The Department Model is assigned to the ‘ModelType’ property of the repeater. This property is available to all DataBound controls. This allows us to define the type of data that is bound to the control and also allows to bind properties of the Model inside the control. The above code defines ‘ItemTemplate’ inside the repeater control which refers to the ‘DepartmentDetails.aspx’ by passing DeptNo value using QueryString to it.


Step 5: Go to the Departments.aspx.cs code behind, and write the following code:

The above code sets the datasource property for the repeater control.


Step 6: View the Departments.aspx inside the browser and the following result will be displayed:  
In your OS, observe the lower right corner of the System Tray. Instead of the ASP.NET Development server, ASP.NET 4.5 uses IIS Express as shown below:  





Step 7
: In Step 4, we added the repeater control which has the ItemsTemplate and contains an <a href=””> to navigate to DepartmentDetails.aspx using a query string. This page is designed for displaying details of a particular Department. Open DepartmentDetails.aspx in the ‘Source’ view and add a DetailsView web UI databound control inside it. As explained Step 4, we need to assign the ModelType property of this control to ‘Department’ model.

All those who have used controls like DetailsView or FormView knows that these control are used for performing DML operations. Now to perform DML operations in earlier versions of ASP.NET i.e. from 2.0 to 4.0 we used to make use of ObjectDataProvider and this provider was usually configured using Get,Insert,Update and Delete methods form the source object. However the ASP.NET 4.5 DataBound controls e.g. GridView, FormView, DetailsView etc, exposes the following properties:

- SelectMethod: Used to make call to a method which returns IEnumarable.
- InsertMethod: Used to make call to a method which performs Insert operation.
- UpdateMethod: Used to make call to a method which performs Update operation.
- DeleteMethod: Used to make call to a method which performs Delete operation.

Configure the DepartmentDetails.aspx as shown below:


Step 8: Open the DepartmentDetails.aspx.cs and add the following code in it:    


Now carefully have a look at the above methods. None of these methods make use of any of the UI controls in the user interface. All these methods strictly work on Model objects and this feature drastically reduces additional coding. One more important fact is, if you observe the ‘GetDepartment()’ method, it has defined the ‘DeptNo’ input parameter with the QueryString Value provider. This automatically reads the DeptNo in the QueryString and displays the Department details inside the DetailsView.

Note: In previous versions of ASP.NET we could have done this using Request.QueryString[“DeptNo”]

Step 9: Now open Site.Master and add the following menu item:

<asp:MenuItem NavigateUrl="~/Department/Departments.aspx" Text="Departments"/>

Step 10: Make Default.aspx as a startup page and run the application. You will see the Default.aspx with Department and Employee menu. Once you click on ‘Department’ menu, Departments.aspx will be displayed. Now click on any Department and you will be transferred to ‘DepartmentDetails.aspx’ as below:

The QueryString has the DeptNo and based upon the value of the DeptNo, the DetailsView will display the  Department details. Here you can now test the Update and New (insert) functionality.

Check out the second part of this article ASP.NET 4.5: Filtering using Model Binding in ASP.NET Web Forms

Conclusion: The Model binding feature provides facility to the developers to develop Webforms which can be independent from the Model

 

 

 

 

 

 

 

 



ASP.NET 4 Hosting :: Html Encoded Expressions in ASP.NET 4.0

clock November 17, 2011 06:09 by author darwin

Introduction

We all know <%=expression%> features in asp.net. We can print any string on page from there. Mostly we are using them in asp.net mvc. Now we have one new features with asp.net 4.0 that we have HTML Encoded Expressions and this prevent Cross scripting attack as we are html encoding them.

ASP.NET 4.0 introduces a new expression syntax <%: expression %> which automatically convert string into html encoded. Let’s take an example for that.
I have just created an hello word protected method which will return a simple string which contains characters that needed to be HTML Encoded. Below is code for that.


protected static string HelloWorld()
{
   return "Hello World!!! returns from function()!!!>>>>>>>>>>>>>>>>>";
}

Now let’s use the that hello world in our page html like below. I am going to use both expression to give you exact difference.

<form id="form1" runat="server">
<div>
   <strong><%: HelloWorld()%></strong>
</div>
<div>
   <strong><%= HelloWorld()%></strong>
</div>
</form>

Now let’s run the application and you can see in browser both look similar. 



But when look into page source html in browser like below you can clearly see one is HTML Encoded and another one is not.



Cool, right?? Happy Programming.



ASP.NET Hosting :: How to Connect to ASP.NET Using MySQL 5.0 - Part II

clock November 8, 2011 05:56 by author darwin

Please stay focus in the first part of this article. In this article, we will focus on taking advantage of the new support for stored procedures in MySQL 5.0. We will be building upon the example application created in Part 1, so please refer to the scripts in the previous article if you wish to create the sample database and ASP.NET application.

MySQL Stored Procedures

A stored procedure is made up of one or more SQL statements or commands and is stored within the database. Stored procedures can be used to perform any type of database operation such as retrieving one or more rows, inserting, updating, deleting data, or perhaps multiple database operations at once.


Before moving on, let’s take a look at creating a stored procedure. Launch MySQL Query Browser, connect to your versedb database, open a new Script Tab, and execute the following script.

DELIMITER $$

DROP PROCEDURE IF EXISTS `versedb`.`usp_Verse_GetList`$$
CREATE PROCEDURE `usp_Verse_GetList`()
BEGIN
  SELECT  verse_id,
          verse_text,
          verse_ref
  FROM    verse
  ORDER BY
          verse_ref DESC;
END$$

DELIMITER ;


This simple stored procedure retrieves all the rows in the verse table ordered by verse reference in descending order. To see this stored procedure in action, open a new Query Tab and execute the following command. 

CALL usp_Verse_GetList(); 

What you should see (assuming you have data in your verse table from Part 1), is a list of all the rows in your table ordered by the verse reference in descending order, just as you might expect.

One of the primary benefits of using stored procedures is that SQL statements and logic can be maintained apart from the applications that use them. So, instead of embedding SQL commands in your application, your application only needs to know how to execute the stored procedures it needs.

Stored procedures also support parameters. In this way, a single stored procedure can be used in many scenarios without having to be modified. For example, you can create a stored procedure that can retrieve a single row in your table based upon a primary key value passed as a parameter.

DELIMITER $$

DROP PROCEDURE IF EXISTS `versedb`.`usp_Verse_Get_By_Id`$$
CREATE PROCEDURE `usp_Verse_Get_By_Id`(v_id INT)
BEGIN
  SELECT  verse_id,
          verse_text,
          verse_ref
  FROM    verse
  WHERE   verse_id = v_id;
END$$


To see the stored procedure in action, execute the following command.

CALL usp_Verse_Get_By_Id(2);

What you should see is a single row returned from the database where the verse_id field is equal to 2. To retrieve a different row, you would simply replace the value 2 with a different valid primary key value. If you specify a value that does not exist in the table, then no rows would be returned.

A couple more things to mention: it is possible to define output parameters as well as for input, and stored procedures do not have to return any rows. We will look at an example of both in a later article, but imagine the scenario of creating a stored procedure to insert a new row into a table. You might pass the values for the row as input parameters, return the new primary key ID assigned to the inserted row as an output parameter, and would not need to return any rows of data.

Calling MySQL Stored Procedures from ASP.NET


Executing a stored procedure using ASP.NET is nearly identical to executing straight SQL. Unless a procedure requires parameters, you only need to provide the name of the stored procedure in the command text, and specify the CommandType property is of type StoredProcedure

// Get the MySQL connection string stored in the Web.config
string cnnString = ConfigurationSettings.AppSettings["ConnectionString"];

// Create a connection object and data adapter
MySqlConnection cnx = new MySqlConnection(cnnString);
MySqlDataAdapter adapter = new MySqlDataAdapter();

// Create a SQL command object
string cmdText = "usp_Verse_GetList";
MySqlCommand cmd = new MySqlCommand(cmdText, cnx);

// Set the command type to StoredProcedure
cmd.CommandType = CommandType.StoredProcedure;

// Create and fill a DataSet
DataSet ds = new DataSet();
adapter.SelectCommand = cmd;
adapter.Fill(ds);

One difference you might notice from the previous article is retrieving the connection string from the web.config using ConfigurationSettings.AppSettings
, which is typically best practice. If you are not familiar with this technique, you would simply create an block in your web.config that looks like the following

<appsettings>
  <add key="ConnectionString" value="Server=localhost;Port=3306;Database=versedb;Uid=root;Pwd=mySecret" />
  </add>
</appsettings>


You would need to add the section directly after and before. If you already have an section defined, you only need to insert the node for the connection string.

Executing Stored Procedures with Parameters

To execute a stored procedure with parameters, you must create and add a
MySqlParameter object to the MySqlCommand.Parameters collection for each required parameter.  Also, parameter names in MySQL use a prefix of "?" which is similar to Microsoft SQL Server's use of "@."


// Hard-coding the Verse ID for example only
int verseID = 2;

// ...Code to create connection goes here...

// Create a SQL command object
string cmdText = "usp_Verse_Get_By_Id";
MySqlCommand cmd = new MySqlCommand(cmdText, cnx);

// Set the command type to StoredProcedure
cmd.CommandType = CommandType.StoredProcedure;

// Create the verse ID parameter
MySqlParameter param;
param = new MySqlParameter("?v_id", MySqlDbType.Int32);
param.Value = verseID;
param.Direction = ParameterDirection.Input;
cmd.Parameters.Add(param);

// ...Code to build DataSet goes here...


Of course, you would probably wrap all of this code in a method that takes a verseID as a parameter and returns a DataSet or DataRow

Summary

In summary, you might think of stored procedures as a public method exposed by your database that encapsulates your SQL code. You can make any change to the stored procedure’s code, and as long as the name of the procedure and its parameters, if any, do not change (in other words, the “method signature” to continue our illustration), there would be no need to modify your ASP.NET application.

Hopefully this gives you a starting point for using MySQL stored procedures.  However, we have only begun to scratch the surface of this very powerful feature.  In the future, we will look at creating more complex stored procedures, and using stored procedures to insert, update, and delete data in your database.



ASP.NET Hosting :: How to Connect to ASP.NET Using MySQL 5.0 - Part I

clock November 8, 2011 05:31 by author darwin

In this series of articles, I want to introduce you to using MySQL 5.0 with ASP.NET.  I hope to cover the most common uses for MySQL, as well as take advantage of some of the new features in version 5.0.  To do this, we will look at creating a database of Bible verses and ASP.NET pages to view and manage the verses.

To begin development, you will need to have the following tools. 

Required Components:

-
.NET Framework 1.0 or higher

-
MySQL 5.0 database server
-
MySQL Connector/Net 1.0.6 or higher

Optional Components:

-
MySQL Query Browser 1.1.15 or higher
-
MySQL Administrator 1.1 or higher
-
Visual Studio 2002 or higher

MySQL database server comes with command-line utilities to administer and develop MySQL.  However, MySQL Query Browser and MySQL Administrator are great utilities that will make your life much easier.  Visual Studio is not required, but certainly makes developing ASP.NET applications much easier.  Alternatively, you can use the free ASP.NET Web Matrix or simply create your ASP.NET web pages using any text editor. 

Installing each of these components is outside the scope of this article.  Please refer to the documentation provided with each for installation and configuration instructions.

Setting up the Database

Here are the scripts you’ll need to create the verse schema (database).  To execute the scripts, you’ll need to use the mysql command line utility or MySQL Query Browser application.

CREATE DATABASE versedb;
CREATE TABLE `verse` (
  `verse_id` int(10) unsigned NOT NULL auto_increment,
  `verse_text` varchar(1024) NOT NULL default '',
  `verse_ref` varchar(50) NOT NULL default '',
  PRIMARY KEY  (`verse_id`)
)


As you can see, we are going to work with just a single table named verse to start with.  Before we can get data out of MySQL, obviously we have to put some data in.  Use the following scripts to add two verses to the table.

INSERT INTO `verse` (`verse_text`,`verse_ref`) VALUES
  ('And God is able to make all grace abound to you, so that in all things
  at all times, having all that you need, you will abound in every good work.',
  '2 Corinthians 9:8'),
  ('Whatever you do, work at it with all your heart, as working for the
  Lord, not for men, since you know that you will receive an inheritance from
  the Lord as a reward. It is the Lord Christ you are serving.',
  'Colossians 3:23-24');


Setting Up the Web Site

This article assumes you will set up a virtual directory on your local computer or you will upload the examples to a Web host that supports ASP.NET.  Setting up the test web site locally is outside the scope of this document.  If you plan to develop and debug ASP.NET on your local computer and are not already familiar with setting up Internet Information Server (IIS) or creating virtual directories, you can use the links provided on the Online Resources page to find tutorials that cover this subject.

Connecting to MySQL from ASP.NET

As mentioned before, you will need to download and install the MySQL Connector/Net ADO.NET library.  Once you’ve added the MySql.Data.dll assembly as a reference to your project or placed it in your /bin folder, you are ready to start writing code to access MySQL.  Here is an example of connecting to MySQL and retrieving all of the rows from the verse table into a DataSet.

// Connection string for a typical local MySQL installation
string cnnString =
"Server=localhost;Port=3306;Database=versedb;Uid=root;Pwd=MySecretPassword";

// Create a connection object and data adapter
MySqlConnection cnx = new MySqlConnection(cnnString);
MySqlDataAdapter adapter = new MySqlDataAdapter();

// Create a SQL command object
string cmdText = "SELECT * FROM verse";
MySqlCommand cmd = new MySqlCommand(cmdText, cnx);

// Create a fill a Dataset
DataSet ds = new DataSet();
adapter.SelectCommand = cmd;
adapter.Fill(ds);

// Bind the DataSet
// ... Place your databinding code here ...

If you’re already accustomed to data binding in .NET, you should immediately recognize the similarities.  The only difference is you use the MySqlXxx classes instead of the OleDbXxx or SqlXxx classes. 


Hello World…

The following code provides a simple yet complete example of connecting to MySQL and displaying the data retrieved from the database.  To use this code, add a new Web Form (.aspx) to your ASP.NET project, copy and paste, change the connection string to match your MySQL database user name and password, and save.

<%@ Page language="c#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="MySql.Data.MySqlClient" %>
<html>
<head>
<script runat="server" type="text/javascript">
void Page_Load(object sender, EventArgs e)
{
  if (!IsPostBack)
  {
    BindVerses();
  }
}

private void BindVerses()
{
  try
  {
    // Connection string for a typical local MySQL installation
    string cnnString =
"Server=localhost;Port=3306;Database=versedb;Uid=root;Pwd=myPassword";

    // Create a connection object and data adapter
    MySqlConnection cnx = new MySqlConnection(cnnString);
    MySqlDataAdapter adapter = new MySqlDataAdapter();

    // Create a SQL command object
    string cmdText = "SELECT * FROM verse";
    MySqlCommand cmd = new MySqlCommand(cmdText, cnx);

    // Create a fill a Dataset
    DataSet ds = new DataSet();
    adapter.SelectCommand = cmd;
    adapter.Fill(ds);

    // Bind the DataSet
    VerseRepeater.DataSource = ds;
    VerseRepeater.DataBind();
  }
  catch (Exception ex)
  {
    lblError.Text = ex.Message;
  }
}
</script>

<title></title>    
<style type="text/css">
  body { font-family:Verdana, Arial, Sans-Serif; font-size:small; }
  h1, h2, h3, h4, h5 { font-family:Trebuchet MS, Verdana, Arial, Sans-Serif;
}
  input, textarea { font-family: Verdana, Arial, Sans-Serif; font-size:small;
}
  .Error { font-weight:bold; color:#c00; }
  .VerseList { width:400px; }
  .VerseHeader {
    padding:5px;
    border:1px solid #999;
    background-color:#ddd;
    font-weight:bold;
  }
  .VerseText {
    font-family: Trebuchet MS, Verdana, Arial;
    font-size: small;
    padding:5px 5px 0px 5px;
    border-left:1px solid #999;
    border-right: 1px solid #999;
  }
  .VerseRef {
    font-family: Arial, sans-serif;
    font-style:italic;
    font-size: x-small;
    text-align:right;
    padding:5px 15px 0px 5px;
    border-left:1px solid #999;
    border-right: 1px solid #999;
    border-bottom:1px solid #ccc;
  }
  .VerseFooter {
    border-left:1px solid #999;
    border-right: 1px solid #999;
    border-bottom:1px solid #999;
}
</style>
</head>
<body>

  <form runat="server" method="post" id="Form1">
    <p><asp:label cssclass="Error" enableviewstate="False" runat="server"
id="lblError"></asp:label></p>
    <div class="VerseList">
      <asp:repeater runat="server" id="VerseRepeater">
        <headertemplate>
          <div class="VerseHeader">Verse List</div>
        </headertemplate>
      
        <itemtemplate>
          <div class="VerseText"><%# DataBinder.Eval(Container.DataItem, "verse_text") %></div>
          <div class="VerseRef">--
            <%# DataBinder.Eval(Container.DataItem, "verse_ref") %>
          </div>
        </itemtemplate>
        <footertemplate>
          <div class="VerseFooter"><img width="1" height="2" alt="" src="images/pixel.gif" /></div>
        </footertemplate>
      </asp:repeater>
    
    </div>
  </form>
</body>
</html>



ASP.NET Hosting :: How to Display Images with ASP.NET CheckBoxList Control

clock November 3, 2011 06:49 by author darwin

In this tips I will discuss how you can customize the rendering of ASP.NET CheckBoxList control with images.  Let’s consider a scenarios where you want to show some status images with every checkbox with in a CheckBoxList. Many developers use table with checkbox and images in different cell to display Images with checkbox.  But, we can easily achieve the same using CheckBoxList control itself.

Let’s  consider you have items in a CheckBoxList control.



If you run your web application with above CheckBoxList items, you will get below output



Now you want images instead of the text with the list of checkbox controls. If you look in to the code, as of now, nothing has been written with in NewCheckList_DataBound method.  To enable the adding icon  we have to override the content of items which is being  generating during  data bound. Below is a simple code which will enable to add  icons for every CheckBo  item in the CheckBoxList



What we did is just iterating through each element and override the  item text as per our requirement . Once run, you will get the output as below.



If you want avoid the text, you just need change the override content of item.Text.



So not only the icon, you can add any HTML Content as per requirement.



ASP.NET 4.0 Hosting on our European Data Center

clock November 1, 2011 07:47 by author Administrator

Starting from 7th Nov 2011, ASPHostCentral.com starts to offer a hosting service located in our prestigious Amsterdam (Netherland) Data Center. For further information, please click here.

For all our new customers who wish to have their sites activated on our Amsterdam (Netherland) data center, you must indicate your request on our order form at
https://secure.asphostcentral.com. For our existing customers, a one-time migration fee applies to all requests on our Amsterdam (Netherland) data center and please creates a ticket from our Help Desk to signal your interest.

Our new data center in Amsterdam provides businesses across Europe region. The Amsterdam data center is complemented by new points of presence (PoPs) in Europe that will provide millions of new users with a direct, dedicated path to our Network, providing lower latency and a superior end user experience.

Network Details

Our global network seamlessly integrates three distinct and redundant network architectures—Public, Private, and Data Center to Data Center—into the industry’s first Network-Within-a-Network topology for maximum accessibility, security, and control.

We leverage best-in-class connectivity and technology to innovate industry-leading, fully automated solutions that empower enterprises with complete access, control, security, and scalability. With this insightful strategy and our peerless technical execution, we have created the truly virtual data center—and made traditional hosting and managed/unmanaged services obsolete.

We are proud of our high speed connection. In fact, one of our most frequent compliments from our customers is how fast their site loads... read on and you will see why. When you combine high speed connectivity and high quality equipment, you get a fast and reliable web site. We have invested in the equipment and staff so you can rest assured that your site will load fast every time. We host sites all over the world, and with our multiple backbone connections, your customers will get through to your site fast.

For more details, please visit
ASPHostCentral.com website.



ASP.NET Hosting :: Tips Using ASP.NET Session

clock November 1, 2011 07:00 by author darwin

While working with ASP.NET web application you must be familiar with one of most important state management technique “Session”. ASP.NET Session State is on by default, hence you are paying for memory even if you don’t use it. There are several ways to optimize it.

Tip #1 :  Not using Session State at all ? Then turn it off completely in web.config



Tip #2 : Session is only required for few pages not all over the application 

Then first turn it off for all pages, for that you need to do following entry in web.config



then enable it for a specific page where you required the session



Tip #3 : If you are using Session for Reading Purpose, use Session State as “ReadOnly”

If you are a beginner, you must be wondering what is EnableSessionState=”Readonly” .  Well, if you look at your web application, not all the pages using Session or some of the pages is using session data for reading purpose. If there is no write operation happaning on session, then it’s always better to use session State is “ReadOnly



The session request pass through different httpModule with in HTTPPipeline. Know more details on how session state ReadOnly works , please read the article
Read Only Session State in ASP.NET. A quick summary from the referred article,

The session state module implements a readers – writers  locking mechanism and queues the access to session state values. A page that has session-state write access will hold a writer lock on the session until the request finishes. A page gains write access to the session state by setting the EnableSessionState attribute on the @Page directive to True. A page that has session-state read access — for example, when the EnableSessionState attribute is set to ReadOnly — will hold a reader lock on the session until the request finishes.

You can also set ReadOnly SessionState in web.config as well



Tip #4 : Programmatically Change Session State Behavior when required (ASP.NET 4.0)

We can enable or disabled session state either in web.config or using @Page directive’s   EnableSessionState attributes. But there was no provision to change the session state at runtime till date in ASP.NET. But using  ASP.NET 4.0, we can change the session  state programmatically . The .NET 4.0 framework adds a new method SetSessionStateBehavior  to the HttpContext class for ASP.NET. This method required SessionStatebehavior  value to set the current session mode. To call SetSessionStateBehavior   simply create a new HttpModule by Implementing IHttModule and hook the BeginRequest event. Most important you can only use the SetSessionStateBehavior  until the AcquireRequestState event is fired, because
AcquireRequestState  Occurs when ASP.NET acquires the current state  that is associated with the current request

While calling SetSessionStatebehavior, You can pass the following values as SessionStatebehavior  :

- Default: This is default setting which means  everything works as before
- Disabled: Turned of Session Sate for Current Request.
- ReadOnly: Read only access to Session State;
- Required: Enabled session state for both Read and Write Access



Tip #5 : Compress Session Data while using OutProc Session mode based on Requirements (AP.NET 4.0)

ASP.NET 4.0 comes with a new option for compressing the Session data with Out Process Session mode. To enabling this functionality we need to add “compressionEnabled=”true” attribute with the SessionMode in web.config .



When Compression mode is enabled is web.config, ASP.NET  compress the serialized session data  and passed it to session storage and during retrieval same  deserialization and decompression happens in server side. ASP.NET 4.0 used System.IO.Compression.GZStream class to compress the session mode.



Tip #6 : Use HttpContext.Current.Items for very short term storage instead of Session

You can use HttpContext.Current.Items for very short term storage. By Short term storage means, this data is valid for a single HTTP Request.  There are many confusion around regarding storing data in HttpContext.Current.Items and storing data in Session variable. Items collections of HttpContext is and IDictionary key-value collections and that are shared across a single HTTPRequest. Yes, HttpContext.Current.Items  valid for  a single HTTPRequest.



Cheers…



ASP.NET 4.0 Hosting :: The Reasons Application Pool Recycle

clock October 31, 2011 07:43 by author Administrator

If your ASP.NET application crashes, has an unhandled exception, hangs or otherwise becomes brain-dead, it will cause the application pool to recycle. Sometimes your application pool recycles for no obvious reason. This is usually a configuration issue or it may be caused by your app performing file system operations in the application directory. Many times developers incorrectly set up SqlConnections so that they aren't properly closed and returned to the connection pool, and this can also cause your AppPool to recycle unexpectedly. When your AppPool recycles, you can kiss your InProc Sessions - and everything else -- goodbye.

Application pool settings

Looking at the properties for the application pool in IIS, you'll see the settings for "on purpose" recycling. In IIS6 these are:

- Recycle worker processes (in minutes)
- Recycle worker process (in requests)
- Recycle worker processes at the following times
- Maximum virtual memory
- Maximum used memory

If you're running IIS5 or the IIS5 isolation mode you must look at the processModel element of machine.config. The properties you should pay attention to are:

- memoryLimit
- requestLimit
- timeout

In IIS 7.o, you have Fixed Interval or Fixed # Requests, or Specific Times for recycling. Also, there are Memory -based Maximums for Virtual and Private Memory, and additional items for Configurable and Runtime recycling events including "unhealthy ISAPI".

When an application pool recycles, HTTP.SYS holds onto the client connection in kernel mode while the user mode worker process recycles. After the process recycle, HTTP.SYS transparently routes the new requests to the new worker process. Consequently, the client never "loses all connectivity" to the server; the TCP connection is not lost -- only state is lost (Application, Session, Cache, etc.).

memoryLimit
The default value of memoryLimit is 60. This value is only useful if you have a small amount memory on a 32 bit machine. "60" means 60% of total system memory. So if you have 1 GB of memory your IIS worker process will automatically restart once it hits memory usage of 600 MB.

requestLimit
This setting is "infinite" by default, but if it is set to 8000 for example, then ASP.NET will launch a new worker process once it has handled 8000 requests.

timeout
The default timeout is "infinite". This is where you set the lifetime of the worker process. Once the timeout is reached ASP.NET launches a new worker process, so setting this to "00:30:00" would recycle your application every 30 minutes.

Other properties
Another property within the processModel element that will cause your application pool to recycle is responseDeadlockInterval. If you have a deadlock then that's your main "fix" that you need to worry about -- changing the responseDeadlockInterval setting won't do much to resolve the problem. You need to deal with the deadlock itself, find out why it's happening, and change your code.

File Change Notification

ASP.NET 2.0 depends on File Change Notifications (FCN) to see if the application has been updated, and depending on the magnitude of change the application pool will recycle. If you or your application are adding and removing directories to the application folder, then you will be restarting your application pool every time.

Altering the following files also causes an immediate restart of the application pool:
- web.config
- machine.config
- global.asax
- Any file in the /bin directory or subfolders

Updating .aspx files, etc. causing a recompile eventually triggers a restart of the application pool also. There is a property of the compilation element under system.web called numRecompilesBeforeAppRestart. The default value is 20, meaning that after 20 recompiles the application pool will recycle.

Workaround for the sub-directory issue

If your application actually requires adding and removing sub-directories you can use linkd to create what's called a directory junction:

Create a directory you'd like to exclude from FCN, e.g. c:\inetpub\wwwroot\MyWebApp\MyFolder
Create a separate folder somewhere outside the wwwroot, e.g. c:\MyExcludedFolder
Use linkd to link the two: linkd c:\inetpub\wwwroot\MyWebApp\MyFolder c:\MyExcludedFolder
Now any changes made in the c:\inetpub\wwwroot\MyWebApp\MyFolder will now actually occur in c:\MyExcludedFolder so they will not be sensed by FCN.

Linkd only comes with the Windows XX Resource Kit, which is a pretty big download. But Mark Russinovitch has "junction" which could be even better:
http://www.microsoft.com/technet/sysinternals/FileAndDisk/Junction.mspx  

Is recycling the application pool good or bad?


If your app is coded properly, you shouldn't have to recycle the application pool. However, if you're dealing with a memory leak in your app and you need to buy time to fix it, then recycling the application pool could be a good idea. It's important to understand, though, that's not a "Fix" - it's just a "Band-Aid" until you find out what's causing the problem and fix your code. Unlike as with ASP.NET 1.1, in ASP.NET 2.0 if your app generates an unhandled exception the AppDomain will unload causing an application pool recycle. Consequently it is extremely important to ensure that your code is "best practices" and doesn't generate unhandled exceptions except under the most extreme and unusual conditions



Silverlight 5 Hosting with ASPHostCentral.com

clock October 18, 2011 10:31 by author Administrator

Microsoft Silverlight is a powerful tool for creating and delivering rich Internet applications and media experiences on the web. Silverlight 5 builds on the foundation of Silverlight 4 for building business applications and premium media experiences. Among other capabilities, the Silverlight 5 release candidate highlights dramatic video quality and performance improvements, and features that improve developer productivity.

The final Silverlight 5 release will be available in 2011. The following article is referenced from http://www.microsoft.com/silverlight/future/

Improved media support and rich UI capabilities

- Hardware Decode and presentation of H.264 improve performance for lower-power devices to render high-definition video using GPU support.
- TrickPlay allows video to be played at different speeds and supports fast-forward and rewind. At up to twice the speed, audio pitch correction allows users to watch videos while preserving a normal audio pitch.
- Improved power awareness prevents the screen saver from being shown while watching video and allows the computer to sleep when video is not active.
- Remote-control support allows users to control media playback.
- Digital rights management advancements allow seamless switching between DRM media sources.  

Building next-generation business applications

Silverlight 5 text (bottom) has improved clarity.
Fluid user interface enables smoother animation within the UI. Inter-Layout Transitions allow developers to specify animations to apply when elements are added, removed or re-ordered within a layout. This provides smoother user experiences when, for example, items are inserted into a list.

Text improvements make it possible to build rich magazine-style text layouts:

- Multicolumn text and linked text container allow text to flow around other elements.
- Tracking/leading set precisely how far apart each character is for full creative control.
- Text clarity is improved with Pixel Snapping.
- Text layout performance is significantly improved.
- OpenType support has been enhanced.

Printing:

- Support for Postscript vector printing enables users to create faster, higher-quality reports and documents, including the ability to create a virtual print view different from what is shown on the screen.

Controls:

- Added support for double-click and Combobox type ahead.

Model View ViewModel (MVVM) and Databinding enhancements allow more work to be done more easily via XAML:

- Debugging support now allows breakpoints to be set on a binding, so you can step through binding failures.
- Implicit DataTemplates allow templates to be created across an application to support a particular type by default.
- Ancestor RelativeSource allows, for example, a DataTemplate to bind to a property on the control that contains it.
- Binding in style setters allows bindings to be used within styles to reference other properties.
- The DataContextChanged event is being introduced. Markup extensions allow code to be run at XAML parse time for both properties and event handlers, enabling cutting-edge MVVM support.
- UpdateSourceTrigger allows immediate response to data entry, leveraging ViewModel functionality through databinding.
- Multiple Window support, enabling user to multi-task various functions within a common application.
- CustomTypeProvider, enabling post deployment configuration of product catalogs and other object definitions.
- CustomMarkupExtensions enabling better tooling and code optimization by extending XAML definitions to custom code.  

Silverlight 5 performance improvements

- Reduced network latency by using a background thread for networking.
- XAML parser improvements that speed up startup and runtime performance.
- Support for 64-bit operating systems.
- Reduced network latency by using a background thread for networking.
 
Graphics improvements

- Graphics Processing Unit (GPU) accelerated 3-D application programming interface (API) provides rich graphics on the Web for building advanced data visualizations and rich user experience (UI).
- Immediate mode graphics API allows direct rendering to the GPU.
- Hardware acceleration is enabled in windowless mode with Internet Explorer 9.

Silverlight 5 extends features of the "Trusted Application" model

Silverlight 5 extends features of the ‘Trusted Application’ model to the browser for the first time. These features, when enabled via a group policy registry key and an application certificate, mean users won’t need to leave the browser to perform complex tasks:

- Host HTML content as a web browser control within the Silverlight application. HTML pages, such as help content or e-mail, can be integrated within the application.
- Read and write files to the user’s My Documents folder, making it easier to find media files or create local copies of reports.
- Launch Microsoft Office and other desktop programs. Users can open Microsoft Outlook and create an e-mail message, or send a report to Microsoft Word utilizing the power of Microsoft Office.
- Access devices and other system capabilities by calling into application COM components. Users can access a USB security card reader or a bar-code scanner.
- Enjoy full keyboard support in full screen, which enables richer kiosk and media viewing applications. - - Call existing unmanaged code directly from within Silverlight with PInvoke.

Tools improvements

- Microsoft Visual Studio profiling support including CPU, memory, and thread contention



ASPHostCentral.com - The Importance of having a UNIQUE IP Address on your Website!

clock October 14, 2011 08:07 by author Administrator

What is an IP address?

An IP address is a set of 4 numbers assigned to each device on a computer network. When we apply this definition for the internet, the IP address can be considered a numerical representation of a website address. For example, the domain google.com would go to the IP address 73.14.213.99.

How do IP addresses work?

When you type in a domain name on your browser, your browser will first match that domain name to an IP address. Then, it will access the server at that IP address.

Why would you want a unique IP address for your website?

Websites that have unique IP addresses are more stable and more reliable.

Disadvantages of sharing an IP address:
Sharing an IP address = Higher chance of website outage

Most web hosting providers nowadays cram thousands of websites onto one server. And because IP addresses are in short supply, they will often have all of the websites that are on a server share one IP address. This practice is quite dangerous as it will jeopardize the stability and functionality of each website on the server.

If your website is sharing an IP address with 1,000 other websites on a server and one of those websites becomes blocked or blacklisted, all 1,000 of those websites, including yours, would be blocked or blacklisted as well.

Advantages of having a unique IP address:
Having a unique IP address = Increased stability and reliability for your website.

By having your own unique IP address, your website would be unaffected by the other websites that are on the same server. If a website on your server gets its IP address blocked or blacklisted, it would not affect your website since it's not sharing the same IP address.

In other words, when you have a unique IP address, your website is unaffected by the other websites that are on the server.

The internet is running out of space

The current IPv4 address pool is almost completely used up.

It was announced in early 2011 that the last batch of IP addresses have been allocated. This last batch of IP addresses will probably be used up towards the end of 2011. The current IPv4 address system has about 4.3 billion addresses. With a growing pool of internet users and internet-connected devices, 4.3 billion IP addresses are not enough to meet today's demand.

Fortunately, researchers have designed a new IP address system - IPv6. This new system has 360 undecillion IP addresses and has been available since 1999. But, it seems like the transition is slow, and we'll be stuck with IPv4 for a while. Here's why:

- Transitioning 4.3 billion IP addresses over to the new IPv6 system will take quite some time.
- Existing equipment will need to be upgraded in order to support the new IPv6 address system.
- Not many Internet Service providers (ISP) support IPv6. This means that if your ISP doesn't support IPv6, then you won't be able to access websites hosted with IPv6 addresses.
- Currently, IPv4 addresses are accessible through all ISP's, whereas IPv6 addresses are not.
With that said, the value of the existing IPv4 addresses are likely going to shoot up before IPv6 comes into play. So, make sure you get your IPv4 address before they run out!



ASP.NET 4.0 & ASP.NET 4.5 Hosting

 

ASPHostCentral is a premier web hosting company where you will find low cost and reliable web hosting. We have supported the latest ASP.NET 4.5 hosting and ASP.NET MVC 4 hosting. We have supported the latest SQL Server 2012 Hosting and Windows Server 2012 Hosting too!

 

Calendar

<<  October 2024  >>
MoTuWeThFrSaSu
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

View posts in large calendar

Sign in