All About ASP.NET and ASP.NET Core 2 Hosting BLOG

Tutorial and Articles about ASP.NET and the latest ASP.NET Core

IIS 8 Hosting - 3 Huge Improvements in IIS 8

clock January 21, 2013 08:20 by author andy_yo

Internet Information Services (IIS) 8 includes many new and improved features that make moving to Windows Server 2012 compelling for organizations that rely on Windows Servers as their web server. For developers and system administrators that are looking to mirror that IIS environment on their workstation for development or testing, IIS 8 gives another reason to move your workstation to Windows 8.

About ASPHostPortal.com

ASPHostPortal.com is Microsoft No #1 Recommended Windows and ASP.NET Spotlight Hosting Partner in United States. Microsoft presents this award to ASPHostPortal.com for ability to support the latest Microsoft and ASP.NET technology, such as: WebMatrix, WebDeploy, Visual Studio 2012, ASP.NET 4.5, ASP.NET MVC 4.0, Silverlight 5 and Visual Studio Lightswitch. Click here for more information

Improvement 1: Centralized SSL Certificate Management

With IIS on Windows 8 or Windows Server 2012, you can take advantage of the SSL certificate management console. This is a central management console that is able to install certificates and work with certificates across all IIS 8 web servers.

This includes the ability to more rapidly bring new servers online by being able to import all certificates that are needed. If a certificate needs to be renewed on multiple systems, it can be done through the IIS 8 certificate management console. You no longer have to log onto each system to update the certificate.

 

Note: Centralized SSL Certificate management is installed as a separate feature. You can install IIS without Centralized SSL Certificate Support. Centralized SSL Certificate Support is in the security section of “Windows Features.”

Improvement 2: Application Initialization

One frustrating problem that many web server admins face is the problem of slow-responding sites as web applications are initializing. A common workaround is to use tools and scripts to “cold start” the applications early in the morning so that the sites are ready to perform: The in-memory cache is loaded, and in some cases the content must be generated, before the IIS server is ready to respond to HTTP requests.

With IIS 8, Application Initialization lets you establish rules for “warming up” sites. For example, you can have larger applications begin the initialization process earlier than smaller applications. You can also configure through application initialization a new splash screen to be displayed in case people find themselves waiting while the application is initializing.

I can see a much better user experience by logging onto a SharePoint site early in the morning and having the first page displayed being a simple “Please wait while this application is being prepared for use” splash screen instead of just a blank page and a spinning circle.

Improvement 3: Dynamic IP Address Restrictions

Restricting access to a website by its IP address is nothing new -- admins have long been able to do that. You can even restrict by a block of IPs in an address range.

The problem that persists is tracking down all of the IP addresses to block. This would usually take a long time of parsing through logs, and even if going through the logs and filtering out the IP addressed were scripted, it is done in a reactive manner.

Instead, using the Dynamic IP Address Restrictions feature in IIS 8 for Windows 8 and Windows Server 2012, you can specify on a per web application level the maximum number of connections that an IP address can create within a certain time frame. And you can also specify the maximum number of attempts that can be made into the IIS 8 server from an IP address within a specific time. Any attempts beyond what is allowed are automatically filtered out, making your web applications and your web server much more resistant to malicious activity.

Dynamic IP Address Restrictions is added as an additional feature of IIS that is not installed by default. To install the feature, open Windows Features, then place a check in the box to select Web Server (IIS) -> Web Server -> Security -> IP and Domain Restrictions. After all that, click Finish.



Windows Server 2012 Hosting - Top 10 Windows Server 2012 Features

clock January 17, 2013 10:26 by author andy_yo

Many IT professionals and system administrators are evaluating the software for deployment Windows Server 2012 since it has been officially available in September 9th, 2012. Here are the top 10 features that we think noteworthy new (or improved) features in Windows Server 2012.

About ASPHostPortal.com

ASPHostPortal.com is Microsoft No #1 Recommended Windows and ASP.NET Spotlight Hosting Partner in United States. Microsoft presents this award to ASPHostPortal.com for ability to support the latest Microsoft and ASP.NET technology, such as: WebMatrix, WebDeploy, Visual Studio 2012, ASP.NET 4.5, ASP.NET MVC 4.0, Silverlight 5 and Visual Studio Lightswitch. Click here for more information

Top 10 Windows Server 2012 Features

1. Data Deduplication

One of the constants of technology and the IT industry is that data storage demands and requirements are increasing exponentially. From ballooning email inboxes to file shares overflowing with documents, just about every enterprise has a need for more efficient. That’s where the new data deduplication features in Windows Server 2012 come in handy.

It works like this: Say you have a large number of VHD (virtual hard disk) files that you need to move. Each of those VHDs has a lot of duplicate (yet identical) files and applications, like minesweeper, Windows calculator, and other accessory applications. Data deduplication removes all of the copies of those applications from those VHDs but one. It then records the redundant data in a separate location in System Volume Information (SVI) and points to the files that serves as the source template. This can free up tremendous amounts of space, especially when applied across thousands of files across your network. Data deduplication works across different computer networks and also across Windows 8 and Windows Server 2012 machines. If you have lots of files and data to store and not enough space – and who doesn’t – this could be the killer feature.

2. GUI-less install options

There are plenty of times when you only want to install only the absolute minimum files and assets you need to run Windows Server, and Windows Server 2012 now includes a default installation option to install the GUI-less server core. You can also now install Windows Server 2012 with a minimal user interface, which means that you have even more ways than ever to install just the Windows Server files you need. This reduces disk space, saves on administration effort, and reduces your attack surface from hackers and other digital malcontents by restricting installed files to the absolute minimum.

3. Hyper-V 3.0

Windows Server 2012 is loaded with new features, but perhaps the feature that has gone through the most radical improvement is the Hyper-V virtualization feature set. Tired of playing catch-up to VMware on the feature front, Microsoft has loaded Hyper-V with an impressive list of improvements. Some of the highlights include support for up to 64 processors and 1TB of RAM per virtual machine, as well as support for up to 320 logical hardware processors and 4TB of RAM per host. VMware vSphere 5.1 evens the playing field in some areas, but the message is clear: Microsoft is doing everything it can to unseat VMware as the virtualization platform of choice in the enterprise.

4. IP Address Management (IPAM)

One of the biggest headaches for many IT professionals is keeping tabs on IP addresses used on their corporate networks. In a bid to end the time-honored practice of storing IP addresses in Excel spreadsheets, IPAM is a new feature in Windows Server 2012 that provides a new internal framework for locating and managing IP address spaces on networks. You can also manage and monitor servers running Domain Name Service (DNS) and Dynamic Host Configuration Protocol (DHCP). It also does automatic IP discovery and provides a host of other IP-related tasks focused on management, monitoring, and auditing.

5. Network virtualization changes

One of the more problematic aspects of virtual machine management and provision is dealing with the rules and limitations of IP address management. Microsoft is making a raft of improvements to network virtualization in Windows Server 2012, all aimed at tackling problems related to IP addresses and virtual machines. This helps pave the way for private cloud adoption, and also removes barriers for more infrastructure as a service (IaaS) adoption easier for internal IT stakeholders and hosting customers to implement.

6. ReFS

The venerable NTFS file system format has been used for more than a decade by Microsoft. Recent demands from virtualization and private cloud computing have pushed NTFS as far as it could go, so Microsoft decided to add new features and revamp existing ones to NTFS. The result is an upgrade to NTFS dubbed Re-FS for resilient file system.

Re-FS adds a bumper crop of new storage features and improvements, with some of the highlights being increased support for larger file and directory sizes, disk scrubbing, data striping for improved performance, enhanced virtualization support, and it takes advantages of all the new storage pool and spaces features in Windows Server 2012.

7. Shared nothing live migration

One of the more impressive new features of Hyper-V 3.0 is shared nothing live migration, which allows you to move VMs from one machine to another without the requirement of having shared storage before making the transfer. This feature can be a boon for smaller IT departments, and it makes it easy to move VMs around without expensive share storage. It one of the most impressive features in Windows Server 2012, and it will help small- to mid-size IT departments become even more agile and responsive to business and customer needs.

8. Storage pools and spaces

Most IT departments have to contend with a dizzying assortment of storage hardware and medium types, from leading-edge SSD drives and spinning disks to removable drives and legacy magnetic reel tape. Making effective use of all those disparate storage formats can sometimes be a Herculean task, especially when you throw in the ever-increasing storage demands that today’s workplaces place on IT departments. Microsoft is hoping to help admins address that by introducing Storage Pools and Spaces, two storage abstractions concepts being introduced in Windows Server 2012.

Storage Pools aggregate these heterogeneous physical storage devices into cohesive units where it’s relatively easy to add storage capacity by adding additional storage. As mentioned previously, the devices in storage pools don’t have to be homogenous from the perspective of either device or storage size; you can mix and match devices and sizes here.

Storage Spaces takes that concept even further by allowing you to create virtual disks that have the same characteristics as physical devices: they can be attached, removed, backed up, and otherwise managed exactly the same as traditional physical disks. But Spaces have even more useful features and capabilities, including enhanced capabilities when combined with virtualization and private cloud solutions. They also have additional capabilities on the backup, recovery, and high-availability front, and improvement in the realm of thin provisioning as well.

9. PowerShell 3.0

PowerShell has been steadily gaining in popularity over the last few years, and Microsoft pulled out all the stops for PowerShell support in Windows Server 2012. More than 2000 PowerShell cmdlets are now included, and the newly enhanced stable of commands allows IT professionals to automate and control more aspects of their Windows Server 2012 environment through the PowerShell command line that ever before. This latest update to PowerShell also included improved web access, the ability to schedule jobs, support for disconnected sessions, enhanced and editable help files, and dozens of other new features.

10. CHKDSK changes

Everyone reading this is probably already intimately familiar with the ubiquitous CHKDSK application, which has been in use in various forms since MS-DOS 1.0. We’ve all stepped out for a cup of coffee when the dreaded CHKDSK disk scan kicks off on a server or client equipped with large disk storage.

Microsoft has responded to this productivity killer by revamping CHKDSK in Windows Server 2012. Rather than spending vast amounts of time laboriously scanning through sectors on large disks, the new and improved CHKDSK now scans disks in two phases: An online phase that detects errors and logs defects (and which also can run in the background), and an actual repair phase that does the actual fixing of corrupted drive data.



ASP.NET MVC 4 Hosting - Fixing ASP.NET MVC 4 Web API 404

clock January 16, 2013 08:39 by author andy_yo

For a Web Service providing some REST-style URIs to access the data, I decided to use the ASP.NET MVC 4 Web API. Once developed, tested and deployed I experienced a mysterious 404 on my production server.

The Web API started originally as WCF Web API at CodePlex and is finally fully integrated within the latest .NET framework:

“ASP.NET Web API represents the joint efforts of the WCF and ASP.NET teams to create an integrated web API framework. You can get the bits and find articles, tutorials, samples and videos on the new ASP.NET Web API home page. All you have to do is to..”

The tutorials and examples for the ASP.NET Web API are overall easy to understand and you probably get access to the technology very quickly. After I set up my first Web API, which worked absolutely perfect on Windows 8, developed using Visual Studio 2012 and tested with the IIS Express, I was not able to get the bits executed on the deployment server. It’s a Windows Server 2008 R2, IIS 7.5 and a whole bunch of stuff installed using the Web Platform Installer.

Make sure the .NET Framework is installed. Probably you missed to install the 4.5 framework on the deployment server. As IIS is set up already, once again it is necessary to register ASP.NET for the latest framework by opening your command prompt and type:

C:\Windows\Microsoft.NET\Framework\v4.0.30319>aspnet_regiis.exe -i

Even now, I got the 404. Eventually, I got the tip to check out how the routing of extensionless URLs work in ASP.NET. By adding

<system.webServer>

<modules runAllManagedModulesForAllRequests="true" />

...

</system.webServer>

to the web.config file of my Web API  the routing seems to work fine now.

About ASPHostPortal.com

ASPHostPortal.com is Microsoft No #1 Recommended Windows and ASP.NET Spotlight Hosting Partner in United States. Microsoft presents this award to ASPHostPortal.com for ability to support the latest Microsoft and ASP.NET technology, such as: WebMatrix, WebDeploy, Visual Studio 2012, ASP.NET 4.5, ASP.NET MVC 4.0, Silverlight 5 and Visual Studio Lightswitch. Click here for more information



ASP.NET 4.5 Hosting - ASP.NET Web Pages - Adding Razor Code

clock January 16, 2013 06:18 by author andy_yo

In this article we will learn how to use Razor markup with C# and Visual Basic code


What is Razor?

  • Razor is a markup syntax for adding server-based code to web pages
  • Razor has the power of traditional ASP.NET markup, but is easier to learn, and easier to use
  • Razor is a server side markup syntax much like ASP and PHP
  • Razor supports C# and Visual Basic programming languages

Adding Razor Code

<!DOCTYPE html>

<html lang="en">
<head>
<meta charset="utf-8" />
<title>Web Pages Demo</title>
</head>
<body>
<h1>Hello Web Pages</h1>
</body>
</html>

Now add some Razor code to the example:

Example

<!DOCTYPE html>

<html lang="en">
<head>
<meta charset="utf-8" />
<title>Web Pages Demo</title>
</head>
<body>
<h1>Hello Web Pages</h1>
<p>The time is @DateTime.Now</p>
</body>
</html>

The page contains ordinary HTML markup, with one addition: the @ marked Razor code.

The Razor code does all the work of determining the current time on the server and display it. (You can specify formatting options, or just display the default)


Main Razor Syntax Rules for C#

  • Razor code blocks are enclosed in @{ ... }
  • Inline expressions (variables and functions) start with @
  • Code statements end with semicolon
  • Variables are declared with the var keyword
  • Strings are enclosed with quotation marks
  • C# code is case sensitive
  • C# files have the extension .cshtml

C# Example

<!-- Single statement block -->
@{ var myMessage = "Hello World"; }

<!-- Inline expression or variable -->
<p>The value of myMessage is: @myMessage</p>

<!-- Multi-statement block -->
@{
var greeting = "Welcome to our site!";
var weekDay = DateTime.Now.DayOfWeek;
var greetingMessage = greeting + " Today is: " + weekDay;
}
<p>The greeting is: @greetingMessage</p>


Main Razor Syntax Rules for VB

  • Razor code blocks are enclosed in @Code ... End Code
  • Inline expressions (variables and functions) start with @
  • Variables are declared with the Dim keyword
  • Strings are enclosed with quotation marks
  • VB code is not case sensitive
  • VB files have the extension .vbhtml

Example

<!-- Single statement block  -->
@Code dim myMessage = "Hello World" End Code

<!-- Inline expression or variable -->
<p>The value of myMessage is: @myMessage</p>

<!-- Multi-statement block -->
@Code
dim greeting = "Welcome to our site!"
dim weekDay = DateTime.Now.DayOfWeek
dim greetingMessage = greeting & " Today is: " & weekDay
End Code

<p>The greeting is: @greetingMessage</p>

About ASPHostPortal.com

ASPHostPortal.com is Microsoft No #1 Recommended Windows and ASP.NET Spotlight Hosting Partner in United States. Microsoft presents this award to ASPHostPortal.com for ability to support the latest Microsoft and ASP.NET technology, such as: WebMatrix, WebDeploy, Visual Studio 2012, ASP.NET 4.5, ASP.NET MVC 4.0, Silverlight 5 and Visual Studio Lightswitch. Click here for more information



ASP.NET 4.5 Hosting - ASPHostPortal :: How ASP.NET 4.5 Works with HTML 5

clock December 6, 2012 09:38 by author Jervis

ASP.NET and HTML5 works together and in fact ASP.NET & Visual Studio loves HTML5. You can do everything in HTML5 using ASP.NET server language. This post explains some examples how asp.net works with HTML5.

Example:

Using new HTML5 capabilities in ASP.NET File upload control, First thing remove the text after html in DOCTYPE tag in your aspx page then your document is HTML5.

HTML5 has a notion of uploading multiple files and we can achieve this in asp.net with a property

In the code-behind file you can write something as below to display the names of the files that have uploaded

Instead of looking the images after uploading it to the server, you can see them before uploading using JavaScript, to do this add output html5 element to your page and write below code

The above code uses HTML 5 File reader API to show the images before you upload to the server.

This sample also uses couple of JavaScript files and you can bundle them into one as your application grows you may add more JavaScript files to the project. Minify the two files make a single request or reduce the number of requests to access this file. You can create a JavaScript bundle file as shown below

You can bundle the files at runtime and design time. After bundling it creates three file

Whenever source file changes bundle file changes immediately and now you can refer only one file i.e. bundle file in your page

Even after bundling and minifying, you can debug your JavaScript code with the help of .map file.

Similarly you can minify the css files.

In Visual Studio 2012, you will get intellisense for short-hand notations in CSS.

Assume you have a back-ground image for your master page and it loads for every page in your application, why do you want browser to make a request to image from server? You can do this by embedding the image in your style-sheet by doing the base-64 encoding of the file.

You can optimize the picture without losing the quality to remove the unwanted characters in the byte array as below

Right-click on the image and say Optimize image.

All vendor specific css properties are automatically inserted into CSS when you type the property and hit tab

If you consider writing less instead of CSS, what is less? Less is a superset of css. Any css is a valid less file. With less you can have variables and functions in CSS. Less compiles into CSS.

The function in less looks as below

You can reuse this function wherever you want in the file.

All the above features you get from web essentials extension which you can find from Visual Studio editor

 



ASP.NET 4.5 Hosting - ASPHostPortal :: HTML5 snippets in ASP.NET 4.5

clock November 23, 2012 05:36 by author Jervis

ASP.NET 4.5 added support for HTML5 snippets.

HTML5 introduced more than 25 new semantic tags. Visual Studio already had IntelliSense support for these tags, but Visual Studio 2012 makes it faster and easier to write markup by adding some corresponding snippets, like the ones for the audio and video tags.

To invoke the snippet, press Tab twice when the element is selected in IntelliSense:

  <audio controls="controls">
            <source src="file.mp3" type="audio/mp3" />
            <source src="file.ogg" type="audio/ogg" />
  </audio>

This produces a snippet that you can customize.

Automatic renaming of matching tag when you rename an opening or closing tag

If you rename an HTML element (for example, you change a div tag to be a header tag), the corresponding opening or closing tag also changes in real time.

    <heade>
        <audio controls="controls">
            <source src="file.mp3" type="audio/mp3" />
            <source src="file.ogg" type="audio/ogg" />
        </audio>
    </heade>

This helps avoid the error where you forget to change a closing tag or change the wrong one.

Smart indent

When you press Enter while inside an empty HTML element, the editor will put the insertion point in the right place:

If you press Enter in this location, the closing tag is moved down and indented to match the opening tag. The insertion point is also indented:

 



Press Release - ASPHostPortal.com Announces Newest Support for SharePoint 2013 Hosting

clock November 13, 2012 05:57 by author Jervis

ASPHostPortal.com is a premiere web hosting company that specializes in Windows and ASP.NET-based hosting, proudly announces the new Microsoft product, SharePoint 2013 hosting to all new and existing customers.

As in the SharePoint 2010 product line, SharePoint 2013 Foundation is the core platform of the product. SharePoint 2013 comes with enhancements to the administration and user experience, plus new options for enterprise users to collaborate using social media features. SharePoint Server 2013 is basically Foundation with additional Enterprise services and functionality added on top. You will still get Central administration, basic search, document collaboration, and team sites with Foundation. Here are some new features in SharePoint 2013:

- SharePoint 2013 will bring richer themes and even the ability to add a background image to the page.

- Social capabilities in SharePoint 2013: micro blogs, activity feeds, community sites, following, likes and reputations, etc
- Clearly recognizing the massive rise in use of mobile smart devices, Microsoft has done some nice work to make it easier to access SharePoint content from a mobile device.
- Everything is considered an “App” including lists and document libraries. Microsoft is seemingly ready to go after Apple’s thunder.
- Document collaboration is now built into the team site template.

“With this new release of SharePoint 2013, entrepreneurs and organization will be able to build their impressive website to be on the top of the competition. New features like social capabilities make it easy to share ideas and discover experts you never knew existed.” Said Dean Thomas, Manager at ASPHostPortal. “We pride ourselves on offering the most up to date Microsoft services. We're pleased to launch this product today on our hosting environment.”

ASPHostPortal is one of the Microsoft recommended hosting partners that provides the most stable and reliable Windows web hosting platform. With the new launch of SharePoint 2013 into its feature, it will continue to keep ASPHostPortal as one of the front runners in the web hosting market. For more information about this product, please visit http://www.asphostportal.com.

About ASPHostPortal.com:

ASPHostPortal.com is a hosting company that best support in Windows and ASP.NET-based hosting. Services include shared hosting, reseller hosting, and SharePoint hosting, with specialty in ASP.NET, SQL Server, and architecting highly scalable solutions. As a leading small to mid-sized business web hosting provider, ASPHostPortal strive to offer the most technologically advanced hosting solutions available to all customers across the world. Security, reliability, and performance are at the core of hosting operations to ensure each site and/or application hosted is highly secured and performs at optimum level.



ASP.NET Hosting - ASPHostPortal :: Difference between appSettings and Connection Strings in ASP.NET web.config

clock October 22, 2012 08:59 by author Jervis

Now I will explain differences between appsettings and connection strings in web.config using asp.net.

In web.config file we can store the connection strings in two ways those are
appSettings and connectionStrings

AppSettings in web.config

The AppSettings section in web.config is used to store connection strings, server names, file paths, and other miscellaneous settings needed by an application.


Connection String in web.config

The connection string in web.config is a collection of database connection strings only.

Actually in previous versions of ASP.NET all connection string values are storing in appsettings only. In ASP.NET 2.0 + version new features has introduced such as Session, Membership, Personalization, and Role Manager these will depend on connection strings and stored in the connectionStrings element only.

Difference

The main difference is in appsettings section we can store any data string values including database connection strings also but in connectionStrings section only database connection strings can store those are our application connection strings and new features (Membership, Personalization and Role Manager) connection strings only.

Instead of this there is no much difference between appsettings and connectionStrings.

Reasons why you must trust ASPHostPortal.com

Every provider will tell you how they treat their support, uptime, expertise, guarantees, etc., are. Take a close look. What they’re really offering you is nothing close to what ASPHostPortal does. You will be treated with respect and provided the courtesy and service you would expect from a world-class web hosting business.


You’ll have highly trained, skilled professional technical support people ready, willing, and wanting to help you 24 hours a day. Your web hosting account servers are monitored from three monitoring points, with two alert points, every minute, 24 hours a day, 7 days a week, 365 days a year. The followings are the list of other added- benefits you can find when hosting with us:

- DELL Hardware
Dell hardware is engineered to keep critical enterprise applications running around the clock with clustered solutions fully tested and certified by Dell and other leading operating system and application providers.
- Recovery Systems
Recovery becomes easy and seamless with our fully managed backup services. We monitor your server to ensure your data is properly backed up and recoverable so when the time comes, you can easily repair or recover your data.

- Control Panel
We provide one of the most comprehensive customer control panels available. Providing maximum control and ease of use, our Control Panel serves as the central management point for your ASPHostPortal account. You’ll use a flexible, powerful hosting control panel that will give you direct control over your web hosting account. Our control panel and systems configuration is fully automated and this means your settings are configured automatically and instantly.

- Excellent Expertise in Technology
The reason we can provide you with a great amount of power, flexibility, and simplicity at such a discounted price is due to incredible efficiencies within our business. We have not just been providing hosting for many clients for years, we have also been researching, developing, and innovating every aspect of our operations, systems, procedures, strategy, management, and teams. Our operations are based on a continual improvement program where we review thousands of systems, operational and management metrics in real-time, to fine-tune every aspect of our operation and activities. We continually train and retrain all people in our teams. We provide all people in our teams with the time, space, and inspiration to research, understand, and explore the Internet in search of greater knowledge. We do this while providing you with the best hosting services for the lowest possible price.

- Data Center

ASPHostPortal modular Tier-3 data center was specifically designed to be a world-class web hosting facility totally dedicated to uncompromised performance and security
- Monitoring Services
From the moment your server is connected to our network it is monitored for connectivity, disk, memory and CPU utilization – as well as hardware failures. Our engineers are alerted to potential issues before they become critical.

- Network
ASPHostPortal has architected its network like no other hosting company. Every facet of our network infrastructure scales to gigabit speeds with no single point of failure.

- Security
Network security and the security of your server are ASPHostPortal’s top priorities. Our security team is constantly monitoring the entire network for unusual or suspicious behavior so that when it is detected we can address the issue before our network or your server is affected.

- Support Services
Engineers staff our data center 24 hours a day, 7 days a week, 365 days a year to manage the network infrastructure and oversee top-of-the-line servers that host our clients’ critical sites and services.

 



ASP.NET 4.5 Hosting - ASPHostPortal :: Supporting Asynchronous IO Operations with .NET Framework 4.5

clock October 11, 2012 07:30 by author Jervis

In the earlier versions of .NET framework, writing code to perform asynchronous IO operations was not possible and hence the IO operations had to be synchronous. The problems that the developers were encountering with the synchronous approach were:

1. Unresponsiveness of UI - if the application is a thick client and had to perform file IO operations based on the user actions.

2. Performance issue - In case of back ground process, where it has to process large files.

In .NET Framework 4.0 asynchronous IO provisions were given for classes like StreamReader, StreamWriter, etc. through the methods BeginRead, BeginWrite, etc., involving callbacks. Though it provided a way to write asynchronous code there was yet another drawback--the code complexity!


In .NET Framework 4.5 the IO classes are packed with new Async methods using await and async keywords, which can be used to write straight-forward and clean asynchronous IO code. Below are the advantages of using these new async IO methods.


1. Responsive UI - In Windows apps, the user will be able to perform other operations while the IO operation is in progress.

2. Optimized performance due to concurrent work.
3. Less complexity - as simple as synchronous code.

In this article we look at a few examples of async IO operations in .NET Framework 4.5.


StreamReader and StreamWriter

StreamReader and StreamWriter are the widely used file IO classes in order to process flat files (text, csv, etc). The 4.5 version of .NET Framework provides many async methods in these classes. Below are some of them.


1.ReadToEndAsync
2.ReadAsync
3.ReadLineAsync
4.FlushAsync – Reader
5.WriteAsync
6.WriteLineAsync
7.FlushAsync – Writer

The code below reads the content from a given list of files asynchronously.

namespace AsyncIOSamples
{
class Program
{
static void Main(string[] args)
{
List<string> fileList = new List<string>()
{
"DataFlatFile1.txt",
"DataFlatFile2.txt"
};
foreach (var file in fileList)
{
ReadFileAsync(file);
}
Console.ReadLine();
}
private static async void ReadFileAsync(string file)
{
using (StreamReader reader = new StreamReader(file))
{
//Does not block the main thread
string content = await reader.ReadToEndAsync();
//Gets called after the async call is done.
Console.WriteLine(content);
}
}
}
}


Now let us try with the ReadLineAsync and read the content from a single file asynchronously.

namespace AsyncIOSamples
{
class Program
{
static void Main(string[] args)
{
ReadFileLineByLineAsync("DataFlatFile1.txt");
Console.WriteLine("Continue with some other process!");
Console.ReadLine();
}
private static async void ReadFileLineByLineAsync(string file)
{
using (StreamReader reader = new StreamReader(file))
{
string line;
while (!String.IsNullOrEmpty(line = await reader.ReadLineAsync()))
{
Console.WriteLine(line);
}
}
}
}
}


In these examples the main point to note is that these asynchronous operations do not block the main thread and are able to utilize the concurrency factor.

A similar example holds good for StreamWriter as well. Here is the sample code, which reads the content from a list of files and writes it to the output files without blocking the main thread execution.

namespace AsyncIOSamples
{
class Program
{
static void Main(string[] args)
{
ProcessFilesAsync();
//Main thread is not blocked during the read/write operations in the above method
Console.WriteLine("Do something else in the main thread mean while!!!");
Console.ReadLine();
}
private static async Task ProcessFilesAsync()
{
List<string> fileList = new List<string>()
{
"DataFlatFile1.txt",
"DataFlatFile2.txt"
};
foreach (var fileName in fileList)
{
string content = await ReadFileAsync(fileName);
WriteFileAsync(content, "Output" + fileName);
}
}
private static async void WriteFileAsync(string content, string outputFileName)
{
using (StreamWriter writer = new StreamWriter(outputFileName))
{
await writer.WriteAsync(content);
}
}
private static async Task<string> ReadFileAsync(string fileName)
{
using (StreamReader reader = new StreamReader(fileName))
{
return await reader.ReadToEndAsync();
}
}
}
}


WebClient

This class is used for data request operations over protocols like HTTP, FTP, etc. This class is also bundled with a bunch of Async methods like DownloadStringTaskAsync, DownloadDataTaskAsync and more.

It doesn't end here but extends to classes like XmlReader, TextReader and many more. I will leave it to the readers to explore them.

Happy reading!

 



ASPHostPortal.com Announces Newest Service Windows Server 2012 Hosting

clock October 10, 2012 07:26 by author Jervis

ASPHostPortal is a premiere web hosting company that specialized in Windows and ASP.NET-based hosting, proudly announces new Microsoft product, Windows Server 2012 hosting to all new and existing customers. The newly released server operating system offers a number of features that can be utilized to benefit developers, resellers and businesses.

Windows Server 2012 offers new and improved features which enable multi-user infrastructure where storage resources, networking and compute are completely remote from other users. There are a number of key features that customers will find useful, including support for asp.net 4.5, Internet Information Services 8.0 (IIS), compatibility with Visual Studio 2012, Visual Studio Express 2012, support for ASP.NET MVC 4, and Entity Framework 5. Other key new features include dynamic IP restriction to help prevent DoS attacks, support WebSockets and node.js, and also CPU Throttling to ensure isolated each client's server usage and Application Initialization to improve user experience of first requests.

“We have always had a great appreciation for the products that Microsoft Offers. With the launched of Windows Server 2012 hosting services, entrepreneurs and organization will be able to build their impressive website to be on the top of the competition.” Said Dean Thomas, Manager at ASPHostPortal. “Within Windows Server 2012 hosting packages, users will have the ability to use Hyper-V in assorted configurations, improved isolation and security, fortified access controls to files and processes and the capability of managing servers as a group.”

ASPHostPortal is one of the Microsoft recommended hosting partner that provide most stable and reliable web hosting platform. With the new launch of Windows Server 2012 into its feature, it will continue to keep ASPHostPortal as one of the front runners in the web hosting market. For more information about new Windows Server 2012 hosting, please visit http://www.asphostportal.com.

About ASPHostPortal.com:

ASPHostPortal.com is a hosting company that best support in Windows and ASP.NET-based hosting. Services include shared hosting, reseller hosting, and sharepoint hosting, with specialty in ASP.NET, SQL Server, and architecting highly scalable solutions. As a leading small to mid-sized business web hosting provider, ASPHostPortal strive to offer the most technologically advanced hosting solutions available to all customers across the world. Security, reliability, and performance are at the core of hosting operations to ensure each site and/or application hosted is highly secured and performs at optimum level.



Cheap ASP.NET 4.5 Hosting

We’re a company that works differently to most. Value is what we output and help our customers achieve, not how much money we put in the bank. It’s not because we are altruistic. It’s based on an even simpler principle. "Do good things, and good things will come to you".

Success for us is something that is continually experienced, not something that is reached. For us it is all about the experience – more than the journey. Life is a continual experience. We see the Internet as being an incredible amplifier to the experience of life for all of us. It can help humanity come together to explode in knowledge exploration and discussion. It is continual enlightenment of new ideas, experiences, and passions


Author Link

 photo ahp banner aspnet-01_zps87l92lcl.png

 

Corporate Address (Location)

ASPHostPortal
170 W 56th Street, Suite 121
New York, NY 10019
United States

Tag cloud

Sign in