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.0 Hosting :: ASP.NET GridView UI Tips and Tricks by using jQuery

clock September 27, 2010 14:52 by author Administrator

This article demonstrates how to create simple UI effects in an ASP.NET GridView control using jQuery. These tips have been tested in IE 7 and Firefox 3.

Set up an ASP.NET GridView as you usually do, binding it to a datasource. For demonstration purposes, here’s some sample markup where we are using the Northwind database and a GridView bound to the SQLDataSource to pull data from the database.

<form id="form1" runat="server">

<div>

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"

        SelectCommand="SELECT [CustomerID], [CompanyName], [ContactName], [Address], [City] FROM [Customers]">

    </asp:SqlDataSource>   

    <br />          

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="CustomerID"

        DataSourceID="SqlDataSource1" AllowPaging="False" AllowSorting="True" >

        <Columns>                          

            <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" ReadOnly="True" SortExpression="CustomerID" />

            <asp:BoundField DataField="CompanyName" HeaderText="CompanyName" SortExpression="CompanyName" />

            <asp:BoundField DataField="ContactName" HeaderText="ContactName" SortExpression="ContactName" />

            <asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" />

            <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />

        </Columns>

    </asp:GridView>

</div>

</form>

The <connectionStrings> element in the web.config will look similar to the following:

      <connectionStrings>

            <add name="NorthwindConnectionString" connectionString="Data Source=(local);Initial Catalog=Northwind;Integrated Security=True" providerName="System.Data.SqlClient"/>

      </connectionStrings>

Note: In most of the tips shown here, we are using a complex jQuery row ‘filter’ suggested by Karl Swedberg to a user in a jQuery forum. This filter is required due to the fact that a GridView does not render (accessibility tags) a <thead> and a <tfoot> by default. For the header, the GridView generates <th>’s inside <tr>. Similarly for the footer, the GridView generates a <table> inside a <tr> and so on. Hence it is required to use additional filters to exclude header and footer rows while adding UI effects on the GridView. These tips have been tried out on a GridView where paging is not enabled. When the paging is enabled, the pager however gets highlighted. We are still working on a solution to prevent the UI effects from being applied on the pager. We will update this article, once we find a solution. If you have a solution that works cross browser, please share it with us.

The link to download the code for all these samples can be found at the end of this article. Let’s see some tips.


1. Highlight an ASP.NET GridView row by clicking on it     

This tip lets you highlight a row when you click anywhere on the row. Clicking back on a highlighted row, removes the highlight.

<head id="Head1" runat="server">

<title>Highlight Row on Click</title>

<script src="Scripts/jquery-1.3.min.js" type="text/javascript"></script>

<script type="text/javascript">

    $(document).ready(function() {

        $("tr").filter(function() {

            return $('td', this).length && !$('table', this).length

        }).click(function() {

            $(this).toggleClass('currRow');

        });

    });

</script>

<style type="text/css">

    .currRow

    {

        background-color:Gray;

        cursor:pointer;

    }   

</style>

</head>

After applying the filter on the rows (to prevent the user from highlighting the Header and Footer row), we use the toggleClass to highlight/remove highlight on the row.

Output:

2. Remove/Hide the Highlighted rows of an ASP.NET GridView

If you want to remove/hide the highlighted rows from the GridView, then here’s how to do so. We have added a HTML button control (Button1) to the form

<input id="Button1" type="button" value="Remove Rows" />

The jQuery is as shown below:

<head id="Head1" runat="server">

    <title>Hide Highlighted Rows>/title>

    <script src="Scripts/jquery-1.3.min.js" type="text/javascript"></script>

    <script type="text/javascript">

        $(document).ready(function() {

            $("tr").filter(function() {

                return $('td', this).length && !$('table', this).length

            }).click(function() {

                $(this).toggleClass('currRow');

            });

            $("#Button1").click(function() {               

                var hideRows = $("tr").hasClass("currRow");

                if (hideRows == true) {                   

                    $("tr.currRow").remove();

                }

            });

        });

    </script>

    <style type="text/css">

        .currRow

        {

            background-color:Gray;

            cursor:pointer;

        }   

    </style>

</head>

Here the user first highlights the rows and then clicks on the ‘Remove Rows’ button to remove the highlighted rows

3. Remove/Hide ASP.NET GridView Rows on Mouse Click     

In our previous sample, we were following a two step process of first highlighting multiple rows and then removing them. Let’s say if we want to remove the rows as the user clicks on them, then follow this approach:

    <script type="text/javascript">

        $(document).ready(function() {

                $("tr").filter(function() {

                    return $('td', this).length && !$('table', this).length

                }).click(function() {

                    $(this).remove();

                });

        });       

    </script>

4. Highlight an ASP.NET GridView row on Mouse Hover     

In case you do not want to define a separate style for the row and want to highlight a row on mouse over (instead of the click), follow this tip:

<head id="Head1" runat="server">

    <title>Highlight Row on Hover</title>

    <script src="Scripts/jquery-1.3.min.js" type="text/javascript"></script>

    <script type="text/javascript">

        $(document).ready(function() {

            $("tr").filter(function() {

                return $('td', this).length && !$('table', this).length

            }).css({ background: "ffffff" }).hover(

                function() { $(this).css({ background: "#C1DAD7" }); },

                function() { $(this).css({ background: "#ffffff" }); }

                );

        });

    </script>

</head>

Output:

5. Drag and Drop Rows of an ASP.NET GridView

 

 

 

 

This tip comes very handy when you are presenting a set of data in a GridView and want to rearrange rows at runtime. We are using the Table Drag and Drop Plugin for this example and it’s as simple as calling tableDnD() on the table. This plugin enables drag/drop on a table.

<head runat="server">

    <title>Drag Drop Rows</title>

    <script src="Scripts/jquery-1.3.min.js" type="text/javascript"></script>

    <script src="Scripts/jquery.tablednd_0_5.js" type="text/javascript"></script>

    <script type="text/javascript">

        $(document).ready(function() {

            $("#GridView1").tableDnD();

        });

</script>

</head>

Output:

Before Drag

After Drop - dragging row with Customer ID ‘ANATR’ below ‘BLONP’

That’s it for now. We saw some UI tips that can be applied to an ASP.NET GridView using jQuery. Stay tuned to see some more in the forthcoming articles. We are also planning to write an article to store these UI changes when the user paginates through the Grid or a postback occurs

 

 

 

 



ASP.NET MVC Hosting :: ASP.NET MVC Model Binder for Repositories

clock September 21, 2010 08:11 by author Administrator

How do you take the values posted by an HTML form and turn them into a populated domain entity? One popular technique is to bind the POST values to a view-model and then map the view-model values to an entity. Since your action method’s argument is the view-model, it allows you to decide in the controller code if the view-model is a new entity or an existing one that should be retrieved from the database. If the view-model represents a new entity you can directly create the entity from the view-model values and then call your repository in order to save it.  In the update case, you can directly call your repository to get a specific entity and then update the entity from the values in the view-model

However, this method is somewhat tedious for simple cases. Is a view-model always necessary? Wouldn’t it be simpler to have a model binder that simply created the entity for you directly? Here’s our attempt at such a binder:

public class EntityModelBinder : DefaultModelBinder, IAcceptsAttribute
{   
readonly IRepositoryResolver repositoryResolver;
    EntityBindAttribute declaringAttribute;

    public EntityModelBinder(IRepositoryResolver repositoryResolver)
    {
        this.repositoryResolver = repositoryResolver;
    }

    protected override object CreateModel(
        ControllerContext controllerContext,
        ModelBindingContext bindingContext,
        Type modelType)
    {
        if (modelType.IsEntity() && FetchFromRepository)
        {
            var id = GetIdFromValueProvider(bindingContext.ValueProvider, modelType);
            if (id != 0)
            {
                var repository = repositoryResolver.GetRepository(modelType);
                object entity;
                try
                {
                    entity = repository.GetById(id);
                }
                finally
                {
                    repositoryResolver.Release(repository);
                }
                return entity;
            }
        }

        // Fall back to default model creation if the target is not an existing entity
        return base.CreateModel(controllerContext, bindingContext,
odelType);
    }

    private static int GetIdFromValueProvider(IValueProvider valueProvider, Type modelType)
    {
        var result = valueProvider.GetValue(modelType.GetPrimaryKey().Name);
        return (result == null) ? 0 : (int)result.ConvertTo(typeof(Int32));
    }

    public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
    {
        var model = base.BindModel(controllerContext, bindingContext);
        ValidateEntity(bindingContext, controllerContext, model);
        return model;
    }

    protected virtual void ValidateEntity(
        ModelBindingContext bindingContext,
        ControllerContext controllerContext,
        object entity)
    {
        // override to provide additional validation.
    }

    private bool FetchFromRepository
    {
        get
        {
            // by default we always fetch any model that implements IEntity
            return declaringAttribute == null ? true :
declaringAttribute.Fetch;
        }
    }

    public virtual void Accept(Attribute attribute)
    {
        declaringAttribute = (EntityBindAttribute)attribute;   
    }

    // For unit tests

    public void SetModelBinderDictionary(ModelBinderDictionary modelBinderDictionary)
    {
        Binders = modelBinderDictionary;
    }
}


We have simply inherited ASP.NET MVC’s DefaultModelBinder and overriden the CreateModel method. This allows us to check if the type being bound is one of our entities and then grabs its repository and gets it from the database if it is.

Now, We are most definitely not doing correct Domain Driven Development here despite our use of terms like ‘entity’ and ‘repository’. It’s generally frowned on to have table-row like settable properties and generic repositories. If you want to do DDD, you are much better off only binding view-models to your views

 



Web Deployment with Visual Studio 2010 and IIS7

clock September 6, 2010 11:03 by author Administrator

Today, deploying a web application is not as easy as it should be. Whether you are deploying your web to a shared hosting environment and paying monthly to maintain it OR whether you have a web server/s managed by your enterprise, there are a lot of manual steps involved in getting your application from point A to point B.

If you are deploying your web application to a shared hoster then today you have to use technologies like FTP which take a long time to get your web content to the hosted server. After deploying your content you have to manually go to hoster control panel and install your database by running sql scripts and configure various IIS settings like marking a folder as an application to isolate it from the rest of the application.

If you are in an enterprise environment and you want to get a web application deployed you have to systematically document each step that your server admins and DBAs have to perform. In most circumstances you also have to ask your admins to modify the web.config files and go to IIS Manager and configure your settings apart from deploying your web content. Your DBA has to do the necessary steps of running the sql scripts in the right order to get your DB up and running. Such installations many a times take hours to complete.

With Visual Studio 2010 and IIS Web Deployment Tool (MsDeploy.exe / Web Deploy) we are introducing a set of technologies which can seamlessly deploy your applications taking care of the problems stated above. Microsoft Web Deployment Tool is a free download available on the web… You can download MSDeploy from below location:

http://blogs.iis.net/msdeploy/archive/2008/10/29/the-web-deployment-tool-beta-2-is-now-available.aspx

Do note that installing Visual Studio 2010 will automatically install MSDeploy for you. Visual Studio 2010 CTP can be downloaded from below location:

http://www.asp.net/vwd/

Web Deployment feature sets in VS 2010 can be broken down into following major areas:

1. Web Packaging - VS 2010 uses MSDeploy to create a .zip file for your application which we call as a web package. This file contains meta data + the below artifacts

· All of your IIS Settings (e.g. application pools, error pages etc)
· Web Content (e.g. .aspx, .ascx, .js, images etc)
· SQL Server DB
· Various other artifacts like Security Certs, GAC Components, Registry etc

A web package can then be taken to any server and installed either via IIS Manager UI Wizard or even via command line or API for automated deployment scenarios.

2. Web.Config Transformation – With VS 2010 web deployment we are introducing XML Document Transform (XDT) which will allow you to transform your development time web.config file to production/deployment time web.config file. The transformation is controlled by web.config TRANSFORM files named web.debug.config, web.release.config etc. The naming of these files is tied to the MSBuild configuration you are trying to deploy. The transform file will need just the changes that you really want to make to your deployed web.config… You can control the type of changes by instructing the XDT engine using simple and easy to understand syntax…

e.g. the below syntax in web.release.config will replace the connectionString section with new values in the web.config file which is produced for deployment of your release configuration.

3. DB Deployment – VS 2010 allows you to deploy your application along with all of its dependencies including database dependencies on SQL Server. Just by providing the connection string of your source database VS10 will automatically script its data/schema and package it for deployment. VS will also allow you to provide custom .sql scripts and also sequence them correctly to run on the server. Once your DB is packaged along with your IIS Settings and web content you can choose to deploy it to any server by providing the connection string at the install time.

4. 1-Click Publish - VS 2010 will allow you to not only package your web applications with all of its dependencies but also use IIS remote management service to publish the application to remote server. VS 10 will now allow you to create a publish profile of your hoster account or of various testing servers and save your credentials securely so that going forward you can deploy to any of these publish profiles with just one click using Web One Click toolbar. With VS 10 you will also be able to publish using MsBuild command line so that you can configure your team build environment to include publishing in continuous integration model

 



ASP.NET 4 Hosting :: Working with a Database using Model-First Development Technique

clock March 2, 2010 11:15 by author Administrator

Introduction


The upcoming release of Visual Studio 2010 will contain the Entity Framework 4 which is Microsoft's second release of the Entity Framework.  The new and improved EF4 contains a boat load of new features which many developers have suggested after using version 1.  It also comes closer to the features offered in other Object-Relational Mapping tools such as NHibernate.  Object-Relational Mapping tools are used to eliminate much of the tedious code needed to have an application persist and retrieve data from a database.  The developer uses a visual interface to build classes that map to tables, relationships, stored procedures, and other objects in a database.  One of the great new features of EF4 is the ability to create an ADO.NET Entity Data Model and then build the database from the model.  Previously the developer needed to create the database first and then generate the model.  EF4 still supports reverse engineering a database but being able to use Visual Studio to design a database based off of an object model is a big step forward with this tool.

Today, we are going to discuss a way to create a database using Model-First Development Technique. ASPHostCentral.com, as the premier ASP.NET and Windows Hosting provider, proudly presents this article to anyone and we believe it will help many ASP.NET communities; especially to those who are using ASP.NET 4 Framework. In case you are looking for ASP.NET 4 Hosting, you can always consider ASPHostCentral.com and you can start from our lowest Standard Plan @$4.99/month to host your WCF-service site.

The goal of this article is to show you how to create an ADO.NET Entity Data Model using the Entity Framework 4.  This article uses Visual Studio 2010 Beta 2 so some of the steps may change once the final version is released to production.  Future articles will build upon this application to dive deeper into the EF4 to demonstrate how to query and display data, incorporate stored procedures, customize the classes generated by the EF4, and much more.


Creating a Database using Model-First Development


Step 1: Create a New Solution

1. Launch Visual Studio 2010 Beta 2
2. Click the New Project link on the Start Page.  The New Project dialog box should appear
3. Click on the Visual C# node from the tree view of installed templates
4. Select Empty ASP.NET Web Application from the list of templates
5. Enter OrderSystem for the project name and click the OK button

Visual Studio will create a solution file in the folder you specified and also create a sub folder that contains the web site's project file and config files


Step 2: Create an ADO.NET Entity Data Model

The next step is to create the ADO.NET Entity Data Model.  For this application we'll model the concept of users and addresses.  A user can have more than one address so we'll build an entity data model that models this relationship

1. Right click on the OrderSystem project in the Solution Explorer and select Add à New Item…
2. Click the Data node under the Visual C# node in the Installed Templates tree
3. Select the ADO.NET Entity Data Model template
4. Change the name to OrderDB.edmx and click the Add button
5. Visual Studio will display the Entity Data Model Wizard.  This is where you can decide to build the model from an existing database or create the model first and then build the database
6. Choose Empty model from the wizard and click the Finish button

The OrdersDB.edmx file will be added to your project and the file will be displayed in the Entity Framework Designer


Step 3: Create the Entities and Associations


The next step is to model the user and user's addresses relationship. Let's first create the user entity.

1. Right click on the Entity Data Model Designer and select AddàEntity… from the pop-up menu
2. The Add Entity dialog box should appear.  Enter UserAccount for the Entity name.  Notice that as you type the Entity name the Entity Set name pluralizes the Entity name.  Think of the Entity name as the class that represents a record and the Entity set as the class that represents the table of those records
3. By default the Entity Framework will create a Primary Key called Id.  If you wish to not create a primary key you can uncheck the Create key property checkbox from the dialog box.  For this example we want a primary key so leave the box checked
4. Click the OK button. The UserAccount entity will be added to the entity diagram
5. The next step is to add properties to this entity. Properties will map to fields in a table. We'll first add the First and Last name properties
6. Right click on the UserAccount entity and select AddàScalar property from the pop-up menu
7. Change the property name to FirstName
8. In the properties window change the MaxLength to 50. Scalar properties are strings by default
9. Add another property called LastName the same way and set its MaxLength to 50

The next step is to add and insert date and update date properties.  I like to have the inserted and updated dates on every entity just for the sake of trouble shooting.  These are two properties that will be added to every entity so it is the perfect candidate for a Complex Type.  A Complex Type allows you to define a set of properties and then associate them with multiple entities.

10. In the Model Browser window, left click on the Complex Types nodes.  Sometimes you have to click more than once for the node to be selected.  I'm using Beta 2 so hopefully this will be fixed when it goes live.  Once the node is selected right click and select Create Complex Type from the pop-up menu



11. Change the name of the complex type to AuditFields
12. Right click on the AuditFields complex type in the Model Browser and select AddàScalar PropertyàDateTime from the pop-up menu
13. Change the name to InsertDate
14. Follow the same steps to add the UpdateDate property to the complex type
15. Now you can add the Complex property to the UserAccount entity.  Right click the UserAccount entity and select AddàComplex Property from the pop-up menu
16. Change the name to AuditFields.  The type should have already defaulted to AuditFields

When the database is created from this entity it will contain the two audit fields defined in the complex type.Now let's add the address entity.  A user can have more than one address so there is a one-to-many relationship between these two entities

17. Right click the designer and select AddàEntity from the pop-up menu
18. Change the name to Address and then click the OK button
19. Add scalar properties to the Address entity for Address1, Address2, City, State, and Zip.  All of these properties should be strings with lengths of 50, 50, 50, 2, and 5 respectively
20. Change Address2 to be nullable by settting the Nullable property to True in the properties window.  All other properties are required
21. Now add the Audit Fields to this entity by right clicking the Address entity and selecting AddàComplex Property from the pop-up menu.  Set the name to AuditFields and the type to AuditFields

The next step is to create an association between the UserAccount and Address entities.

22. Right click on the UserAccount entity and select AddàAssociation from the pop-up menu
23. The Add Association dialog appears.  It assumes correctly that you want to create a one-to-many relationship between these two entities.  You use the Multiplicity drop down to define the variations of relationships but for this example you can leave the defaults and click the OK button.  Notice that a UserAccountId property was added to the Address table

Step 4: Generate the Database

Now that the entities are defined we can create the database.  Visual Studio makes this quite simple.  A script is generated with the correct DDL statements to create tables, indexes, and relationships which you can then execute against your database

1. Right click on the Designer and select Generate Database from Model… from the pop-up menu.  The Generate Database Wizard will appear
2. Click the New Connection… button
3. Enter your Server Name. Choose either User Windows Authentication or Use SQL Server Authentication.  Whichever you choose you need a user that has permissions to create a database on the server.  For this example I'll use Windows Authentication
4. Enter OrderSystem for the name of the database and click the OK button
5. You should get a message stating "The database 'OrderSystem' does not exist or you do not have permissions to see it.  Would you like to attempt to create it?"  Click the Yes button
6. The database should be created and you'll be returned to the Generate Database Wizard dialog.  Click the Next button
7. The wizard will now generate the DDL statements needed to create this database
8. Click the Finish button
9. A new file will be added to the project called OrderDB.edmx.sql. The file contains the DDL statements to create the database.  The text of the file is as follows:
-- --------------------------------------------------

-- Date Created: 01/17/2010 09:39:04

-- Generated from EDMX file: C:\Documents and Settings\VinceVarallo\

-- my documents\visual studio 2010\Projects\OrderSystem\OrderSystem\OrderDB.edmx

-- --------------------------------------------------

 

SET QUOTED_IDENTIFIER OFF;

SET ANSI_NULLS ON;

GO

 

USE [OrderSystem]

GO

IF SCHEMA_ID(N'dbo'IS NULL EXECUTE(N'CREATE SCHEMA [dbo]')

GO

 

-- --------------------------------------------------

-- Dropping existing FK constraints

-- --------------------------------------------------

 

 

-- --------------------------------------------------

-- Dropping existing tables

-- --------------------------------------------------

 

 

-- --------------------------------------------------

-- Creating all tables

-- --------------------------------------------------

 

-- Creating table 'UserAccounts'

CREATE TABLE [dbo].[UserAccounts] (

    [Id] int  NOT NULL,

    [FirstName] nvarchar(50)  NOT NULL,

    [LastName] nvarchar(50)  NOT NULL,

    [AuditFields_InsertDate] datetime  NOT NULL,

    [AuditFields_UpdateDate] datetime  NOT NULL

);

GO

-- Creating table 'Addresses'

CREATE TABLE [dbo].[Addresses] (

    [Id] int  NOT NULL,

    [Address1] nvarchar(50)  NOT NULL,

    [Address2] nvarchar(50)  NULL,

    [City] nvarchar(50)  NOT NULL,

    [State] nvarchar(2)  NOT NULL,

    [Zip] nvarchar(5)  NOT NULL,

    [AuditFields_InsertDate] datetime  NOT NULL,

    [AuditFields_UpdateDate] datetime  NOT NULL,

    [UserAccountId] int  NOT NULL

);

GO

 

-- --------------------------------------------------

-- Creating all Primary Key Constraints

-- --------------------------------------------------

 

-- Creating primary key on [Id] in table 'UserAccounts'

ALTER TABLE [dbo].[UserAccounts] WITH NOCHECK 

ADD CONSTRAINT [PK_UserAccounts]

    PRIMARY KEY CLUSTERED ([Id] ASC)

    ON [PRIMARY]

GO

-- Creating primary key on [Id] in table 'Addresses'

ALTER TABLE [dbo].[Addresses] WITH NOCHECK 

ADD CONSTRAINT [PK_Addresses]

    PRIMARY KEY CLUSTERED ([Id] ASC)

    ON [PRIMARY]

GO

 

-- --------------------------------------------------

-- Creating all Foreign Key Constraints

-- --------------------------------------------------

 

-- Creating foreign key on [UserAccountId] in table 'Addresses'

ALTER TABLE [dbo].[Addresses] WITH NOCHECK 

ADD CONSTRAINT [FK_UserAccountAddress]

    FOREIGN KEY ([UserAccountId])

    REFERENCES [dbo].[UserAccounts]

        ([Id])

    ON DELETE NO ACTION ON UPDATE NO ACTION

GO

 

-- --------------------------------------------------

-- Script has ended

-- --------------------------------------------------


It is important to note that the tables weren't added to the database yet.  In order to actually create the tables you need to right click in the OrderDB.edmx.sql file and select Execute SQL from the pop-up menu.  You'll be prompted to log into the server that contains your database.  Once you are logged in the script will execute and the objects will be added to your database


Conclusion

That's all you need to do to create a database using the new Entity Framework's Model First methodology. This is a big improvement over the first edition because it allows you to use Visual Studio to work through the design of you objects first and then VS can figure out how to create the database tables, indexes, and relationships for you.





ASP.NET 4 Hosting :: CORE Services in ASP.NET 4 Framework

clock February 12, 2010 06:34 by author Administrator

Microsoft Visual Studio 2010 and the .NET Framework 4.0 are the next generation development tools and platform for Windows Vista, the 2007 Office System, and the Web. ASPHostCentral.com as the premier Windows and ASP.NET Hosting provider has supported .NET4 Framework in all our hosting environments. The cost to host your .NET4 website/project is priced  as low as $4.99/month ONLY.

On this articles, we will present you the CORE Services that you can find on ASP.NET 4 Framework. You can certainly get this all CORE features on any hosting plans you choose.

The Core Services space has a list of new features as well including simplifying the web.config file, permanent page redirection, session state size reduction, expanding the range of allowable URLs, auto-start Web applications, and the list goes on. We’ll touch on a few here.


Auto-Start Web Applications

Some Web applications have extensive initialization code in the Application_Load method in the Global.asax file that needs to be executed before a site can process its first request. The new Auto-Start scalability featured is aimed at resolving this problem when running ASP.NET 4.0 on IIS 7.5 and Windows Server 2008 R2. Cold-starting IIS 7.5 or recycling an application pool causes IIS 7.5 to reference the applicationHost.config file to determine which applications to restart. Marking an application as auto-start informs IIS 7.5 that ASP.NET 4.0 needs to be notified to start the application.

Adding the following to the applicationHost.config file configures the TakeNoteAppPool application pool for auto-startup.


<applicationPools>
  
<add name="TakeNoteAppPool" 
       
startMode="AlwaysRunning"  />
</applicationPools>

If your application pool contains more than a single application, you can specify which applications get auto-started with the applicationHost.config file in Listing 1. When ASP.NET is in the pre-start state, the type defined in the preloadProvider section of the applicationHost.config file has its Preload method fired.

namespace WhatsNew40
{
  
public class MyInitializationCode:
     System.Web.Hosting.IProcessHostPreloadClient
    {
        
public void Preload(string[] parameters)
        {
            
// Code to run on app start up
        }
    }
}

When the PreLoad method completes, the application is ready to process incoming requests. The new auto-start feature solves the problem of making sure your Web application is ready to accept requests before the first visitor arrives.


Shrinking Session State


Session state can be stored out of process on another server or within SQL Server. Both of these approaches require that the session state information be transmitted across the network to the receiving server. ASP.NET 4.0 introduces a way to reduce the size of that session data by compressing and uncompressing it with the System.IO.Compression.GZipStream class with the compressionEnabled setting.

<sessionState
  
mode="SqlServer"
  
sqlConnectionString="connection string here"
  
allowCustomerSqlDatabase="true"
  
compressionEnabled="true" />


Permanently Redirecting a Page

When you permanently relocate a Web page, you should return a HTTP 301 status code as well as a location header in the HTTP response of the relocated page. The HTTP 301 code will inform search engines and other user-agents that the page has permanently moved.

The new RedirectPermanent feature makes it easy to issue HTTP 301 status codes for permanently moved pages.

Response.RedirectPermanent("deadpage.aspx");


Extensible Output Caching

In its simplest forms, caching allows you to store generated HTML pages in memory. This speeds up response time when cache pages are requested since the entire page lifecycle for the page does not have to be processed. The problem with this approach is that all these items are being stored in your Web server’s memory-memory that may be at a premium for sites with heavy traffic volume

This new feature provides a way for storing those cached HTML assets in any storage mechanism you choose. A custom output cache provider is created as a class deriving from System.Web.Caching.OutputCacheProvider. A web.config entry in the new providers section of the outputCache element contains the details for your new class


Web.config Goes on a Diet

With all the features that have been added to ASP.NET over the years, it was inevitable that the web.config would swell in size. Add in the new features in ASP.NET 4.0 such as routing, AJAX, outputCaching Providers and so on, and the swelling continues. New to ASP.NET 4.0 is the moving of major configuration settings into the machine.config file with applications inheriting these settings.

This allows an application to simply not have a web.config file or to have a very simple one like this one specifying the framework version being targeted.


Listing 1: applicationHost.config file settings for Auto-Start

<sites>
  
<site name="MainSite" id="1">
    
<application path="/"
       
preloadEnabled="true"
       
preloadProvider="AutoLoadData" >
       
<!--  //Additional application settings here// -->
    
</application>
  
</site>
</sites>

  
<!-- //Additional settings here// -->

<preloadProviders>
   
<add name="AutoLoadData "
        
type="WhatsNew40.MyInitialzationCode, WhatsNew40" />
</preloadProviders>



ASP.NET 4 Hosting :: What's NEW in Visual C# 4.0?

clock February 8, 2010 06:18 by author Administrator

Visual C# version 4.0 offers new features that make it easier for you to work in dynamic programming scenarios. Besides dynamic programming, you have support for optional and named parameters, better COM interop support, and contra-variance and covariance. This article will show you how each of these features work and provide suggestions of how they can be applied to help you be more productive.

To help you follow the path of C#, this article looks at the history of C#, today’s use of C#, and helps you understand the future of C# and what the language intends to provide for you. After you understand the theme of C# 4.0, you’ll learn about the new features of C# 4.0. Finally, this article will show you how to create a dynamic object of your own with late-bound calls to dynamic methods based on conventions.

C#: Then and Now

The previous major versions of C# were 1.0, 2.0, and 3.0. There was a minor version 1.1 in April of 2003, but it didn’t significantly change the theme of the 1.0 release.

Microsoft first announced C# on June 16th 2000. It was the first high-level programming language that was built specifically to target the .NET Common Language Runtime. C# 1.0 grew its heritage from C++, but borrowed features from languages such as Delphi, Java, and others. In C# 1.0, Microsoft planned to provide an object-oriented, component-based language that was very simple to use. When Microsoft released C# 1.0 to manufacturing on February 13th 2002, it was an immediate hit and steadily grew in popularity

When C# 2.0 rolled around, Microsoft finally added all of the features that should have been in C# 1.0. For example, generics was huge and is an important part of .NET development today. C# 2.0 also introduced anonymous methods, iterators, and nullable types. An interesting addition to C# 2.0, nullable types was a pre-cursor feature for what was coming in the next version, focusing on data

Most developers work with data, which was the primary theme of C# 3.0. The largest C# 3.0 language addition was Language Integrated Query (LINQ). Most other language features added in C# 3.0 were primarily to support LINQ, but the new features; including implicitly typed local variables, anonymous types, object and collection initializers, lambdas, and extension methods, can have value on their own in development that doesn’t involve LINQ

The next version of C# will be 4.0, which is the focus of this article. C# 4.0 will primarily focus on dynamic programming. The following sections of this article explain the dynamic programming features of C# 4.0 as well as other new features such as optional/named parameters and covariance/contravariance

Why Dynamic Programming?

The dynamic programming story in C# can fall into fulfilling categories of need in the way of multiple-language integration, simpler reflection, access to HTML DOM in Web scenarios, and easier COM interop. Some of these categories of need might not apply to your particular situation, and that’s okay because there isn’t anything that says that you have to use a language feature just because it’s there.

Most C# developers use multiple tools in a single application to accomplish complex tasks. If you’re writing WPF desktop applications, you’re using C# and XAML. It is quite possible that you might find some open source code that solves a problem, but it might be written in another language such as VB or F#. One of the benefits of .NET since its inception is the ability to have cross-language interoperability and the runtime is even called the “Common Language” Runtime (CLR). In recent years, Microsoft has created dynamic languages, such as IronRuby and IronPython, but developers don’t have an easy way to perform interop with dynamic languages. If you have this need, then you’ll welcome the ease with which C# dynamic programming makes interop between C# and dynamic languages possible

When performing reflection to run a method on an object, there are several hoops to jump through, including obtaining a reference to an object type, getting a reference to a member info object, determining the type of bindings to use, and then invoking the member. While reflection has an undeniable coolness factor, it still feels like a hack and that’s where C# 4.0 dynamic methods can help

If you write Silverlight applications, you might have the need today or in the future to access the HTML DOM containing your Silverlight control. C# dynamic programming makes this task easier

Performing COM interop with C# has always been cumbersome; partly because of the need to write extra syntax for conversions, optional parameters, and more. This has left some C# developers with a touch of VB envy because VB has easier COM interop support. One of the purposes of dynamic programming in C# is to help the C# programmer write cleaner syntax in COM interop scenarios

Where do you go for Visual C# 4.0 Hosting?

Basically, you need to look for a host that supports ASP.NET 4.0 Hosting. ASPHostCentral.com is the premier ASP.NET 4 Hosting provider and you can always start from as low as $4.99/month to host your first Visual C# 4.0 project.








ASP.NET 4 Hosting :: URL Routing in ASP.NET 4 Framework

clock January 29, 2010 13:05 by author Administrator

URL routing was a capability we first introduced with ASP.NET 3.5 SP1, and which is already used within ASP.NET MVC applications to expose clean, SEO-friendly “web 2.0” URLs.  URL routing lets you configure an application to accept request URLs that do not map to physical files. Instead, you can use routing to define URLs that are semantically meaningful to users and that can help with search-engine optimization (SEO).

For example, the URL for a traditional page that displays product categories might look like below

http://www.mysite.com/products.aspx?category=software


Using the URL routing engine in ASP.NET 4 you can now configure the application to accept the following URL instead to render the same information:

http://www.mysite.com/products/software

With ASP.NET 4.0, URLs like above can now be mapped to both ASP.NET MVC Controller classes, as well as ASP.NET Web Forms based pages.  You can even have a single application that contains both Web Forms and MVC Controllers, and use a single set of routing rules to map URLs between them.

ASPHostCentral.com proudly announces that we are the first host to offer ASP.NET 4 Hosting with support of Entity Framework 4 to all our new and existing customers and you can start using this newest server from just as low as $4.99/month.

Response.RedirectPermanent() Method

It is pretty common within web applications to move pages and other content around over time, which can lead to an accumulation of stale links in search engines

In ASP.NET, developers have often handled requests to old URLs by using the Response.Redirect() method to programmatically forward a request to the new URL.  However, what many developers don’t realize is that the Response.Redirect() method issues an HTTP 302 Found (temporary redirect) response, which results in an extra HTTP round trip when users attempt to access the old URLs.  Search engines typically will not follow across multiple redirection hops – which means using a temporary redirect can negatively impact your page ranking.  You can use the SEO Toolkit to identify places within a site where you might have this issue

ASP.NET 4 introduces a new Response.RedirectPermanent(string url) helper method that can be used to perform a redirect using an HTTP 301 (moved permanently) response.  This will cause search engines and other user agents that recognize permanent redirects to store and use the new URL that is associated with the content.  This will enable your content to be indexed and your search engine page ranking to improve

ASP.NET 4 also introduces new Response.RedirectToRoute(string routeName) and Response.RedirectToRoutePermanent(string routeName) helper methods that can be used to redirect users using either a temporary or permanent redirect using the URL routing engine.  The code snippets below demonstrate how to issue temporary and permanent redirects to named routes (that take a category parameter) registered with the URL routing system.

You can use the above routes and methods for both ASP.NET Web Forms and ASP.NET MVC based URLs

Summary


ASP.NET 4 includes a bunch of feature improvements that make it easier to build public facing sites that have great SEO.  When combined with the SEO Toolkit, you should be able to use these features to increase user traffic to your site – and hopefully increase the direct or indirect revenue you make from them



Press Release :: ASPHostCentral.com launches ASP.NET 4 Beta 2 Hosting Program

clock November 18, 2009 13:48 by author Administrator

ASPHostCentral.com, an ASP.NET and Windows hosting provider, today announced the supports of ASP.NET 4 Beta 2 Framework hosting on our newest Windows Server 2008 R2 environment.

This ASP.NET 4 Beta 2 Framework will be offered until January 31, 2010 and we will soon replace with the newest full release of ASP.NET4. The Microsoft .NET Framework 4 redistributable package installs the .NET Framework runtime and associated files that are required to run and develop applications to target the .NET Framework 4. This download consists of a new Web-based installer that simplifies the installation process.

This unique opportunity is provided to all our new and existing customers and the cost to host ASP.NET4 Beta 2 project on our environment is priced at $4.99/month only. For more details about this product, please visit our Crystal Report product page at http://www.asphostcentral.com or http://www.asphostcentral.com/ASP-NET4-Hosting.aspx


 

About ASPHostCentral.com:
ASPHostCentral is a premier web hosting company where you will find low cost and
reliable web hosting services. Whether you're an enterprise level business or a small business entity or someone who just wants to host his own personal website - we have a suitable web hosting solution for you.
For more information, visit
http://www.ASPHostCentral.com



.NET4 Hosting :: .NET 4 Feature Focus - Code Contracts

clock November 17, 2009 07:34 by author Administrator

There are many new exciting things that we can find on the latest .NET4 Framework and one of them is the ability to use the “Code Contracts”. ASPHostCentral.com as a premier Windows and .NET Hosting provider, proudly announces that this latest framework has been supported on our entire new servers environment. You can start hosting your .NET4 Beta 2 website from just paying as low as $4.99/month with FREE 1 domain and 1 SQL 2005/2008

Design by contract builds on top of concepts like static typing, where certain actions cannot be performed unless it can be verified at compile time. Contracts usually take the form of pre- and post-conditions such as a parameter or return value never being null or only containing a certain range of values.

Rather than force developers to learn a whole new language such as Spec#, Microsoft is working on a language-agnostic library that can be leveraged by any .NET language. In some ways contracts look like assertions, but they are very different under the covers. Contracts are supported by a combination of static code analysis, which can be both inside and outside the compiler, as well as by testing frameworks. They are also executable, meaning they behave like assertions when running a debug build. Consider this first example:

string GetDescription(int x){

Contract.Requires(x>0);

Contract.Ensures(Contract.Result<string>() != null);

Looking at just the signature, developers only get the static type information "GetDescription requires an integer and returns a string". With the contracts, both developers and tools know "GetDescription requires a positive integer and returns a string that is never null".

In addition to explicit contracts, the contract checker can also support implicit contracts. One such example is division by zero. If a class includes a division of integers where the divisor is a variable, then all code paths must ensure that the variable is never zero or a warning is issued. If the variable in question is a property on a unsealed class, this would require checking in every subclass as well. There are also implicit contracts for dereferencing nulls and array indexes.

To make this easier, there is the concept of an ObjectInvariant method. This special method, which only contains contracts, is injected into the end of each method call to ensure the object's state remains consistent. It is important to note that this applies to all methods, including those in subclasses from other assemblies.

Another time saving device is easy access to old values. In this example the Ensures contract is used in conjunction with the OldValue syntax to make certain that the collection's count property is incremented.

Public Sub Add(value as Object)

Contract.Ensure(Count = Contract.OldValue(Count) + 1)

Even though the contract is written at the top of the method, it will automatically be moved to just before the Return statement by the compiler. As there is some overhead for storing the old value of Count, this sort of check will only occur in debug builds.

In order to support library developers, release builds include a reference assembly. For example, the Widgets.dll assembly would have the bulk of its contracts extracted and placed in the assembly Widgets.Contracts.dll. This allows client developers to use the faster release-style builds while still leveraging the contracts created by the library developers.

One of the more interesting features is that contracts do not just apply to concrete functions. Even interface and abstract methods with no other implementation detail can have contracts. This is done by creating a reference implementation of the interface whose sole purpose is to hold contracts. This reference implementation is linked back to the interface by attributes.

There are no restrictions on the contents of a contract. Since the same contracts are used for both static and runtime checking, a complex constraint that cannot be evaluated by one may still be checked by the other. Contracts can also be extracted by documentation generators.

 



.NET4 Hosting :: Overview of Microsoft .NET Framework 4

clock November 2, 2009 05:19 by author Administrator

The Microsoft .NET Framework 4 redistributable package installs the .NET Framework runtime and associated files that are required to run and develop applications to target the .NET Framework 4. This download consists of a new Web-based installer that simplifies the installation process. ASPHostCentral.com as a premier Windows and .NET Hosting provider, proudly announces that this framework has been supported on all our new servers environment. You can start hosting your .NET4 website from just paying as low as $4.99/month with FREE 1 domain and 1 SQL 2005/2008

Overview

The .NET Framework is Microsoft's comprehensive and consistent programming model for building applications that have visually stunning user experiences, seamless and secure communication, and the ability to model a range of applications.

The .NET Framework 4 works side by side with older Framework versions. Applications that are based on earlier versions of the Framework will continue to run on the version targeted by default.

The Microsoft .NET Framework 4 provides the following new features and improvements:

·         Improvements in CLR and BCL

o    Performance improvement including better multicore support, background garbage collection, and profiler attach on server.

o    New memory mapped file and numeric types

o    Easier debugging including dump debugging, Watson minidumps, mixed mode debugging for 64 bit and code contracts.

·         Innovations in the Visual Basic and C# languages, for example statement lambdas, implicit line continuations, dynamic dispatch, and named/optional parameters.

·         Improvements in ADO.NET

o    Entity Framework, which simplifies how developers program against relational databases by raising the level of abstraction. The Entity Framework has many new features in the .NET 4 Framework. These features include persistence ignorance and POCO support, Foreign Key Associations, lazy loading, test-driven development support, functions in model, and new LINQ operators.

o    Data Services framework consists of a combination of patterns and libraries that enable the consumption of REST-based data services for the web. ADO.NET Data Services has many new features in the .NET 4 Framework. These features include: enhanced BLOB support, Data Binding, Row Count, Feed Customization, Projections, and Request Pipeline improvements. Built-in integration in Microsoft Office 2010 now makes it possible to expose Microsoft Office SharePoint Server data as a data service and access that data using the ADO.NET Data Services client library.

·         Enhancements to ASP.NET

o    New JavaScript UI Templates and databinding capabilities for AJAX.

o    New ASP.NET chart control.

·         Improvements in WPF

o    Added support for Windows 7 multi-touch, ribbon controls, and taskbar extensibility features.

o    Added support for Surface 2.0 SDK.

o    New line-of-business controls including charting control, smart edit, data grid, and others that improve the experience for developers who build data centric applications.

o    Improvements in performance and scalability.

o    Visual improvements in text clarity, layout pixel snapping, localization, and interoperability.

·         Improvements to Windows Workflow (WF) that enable developers to better host and interact with workflows. These include an improved activity programming model, an improved designer experience, a new flowchart modeling style, an expanded activity palette, workflow-rules integration, and new message correlation features. The .NET Framework 4 also offers significant performance gains for WF-based workflows.

·         Improvements to Windows Communication Foundation (WCF) such as support for WCF Workflow Services enabling workflow programs with messaging activities, correlation support. Additionally, .NET Framework 4 provides new WCF features such as service discovery, routing service, REST support, diagnostics, and performance.

·         Innovative new parallel-programming features such as parallel loop support, Task Parallel Library (TPL), Parallel LINQ (PLINQ), and coordination data structures which let developers harness the power of multi-core processors

 



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 2017  >>
MoTuWeThFrSaSu
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345

View posts in large calendar

Sign in