ASP.NET 4.5 and ASP.NET Core 1 Hosting BLOG

Tutorial and Articles about ASP.NET 4.0 and the latest ASP.NET 4.5 Hosting

ASP.NET 4.5 Hosting - Using Bundling and Minification in ASP.NET 4.5

clock April 25, 2013 09:12 by author andy_yo

Is it Important?
Minimising the number of requests the page has to perform can have a considerable effect on your site’s performance. IE6 and IE7 both limit the number of concurrent requests to 2, IE8 can handle up to 6. There is a lot you can to improve the initial load speed speed – one of which is bundling all your CSS and JS into two separate files. How much of a difference it could do. Well, as it turns out up to 30seconds on slower connections.

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

Bundled and Minified vs. Non-Bundled
This is the standard ASP.NET MVC4 app with all the initial JS libraries and CSS. Over a slower connection, the difference can be up to 30seconds. However, even on faster connections, you can save up two seconds just by combining and minifying your scripts.

Image 1 : Non Bundled

Image 2 : Bundled and Minified

Bundling and Minification in ASP.NET 4.5

Luckily for us, the ASP.NET now ships with a new library called System.Web.Optimization. It provides pluggable bundling and minification functionality for your scripts and styles.

It lets you define bundles at application start and pass them to the BundleCollection. Creating a basic new bundle is quite simple. Let’s assume we would like to combine few CSS files

protected void Application_Start()
{
    ... other startup logic
 
    var cssBundle = new StyleBundle("~/Content/themes/base/css")
            .Include("~/Content/themes/base/jquery.ui.core.css",
            "~/Content/themes/base/jquery.ui.resizable.css");   
    BundleTable.Bundles.Add(cssBundle);
}

You can also create bundles for your JavaScript.

protected void Application_Start()
{
    ... other startup logic
 
    var jsValidationBundle = new ScriptBundle("~/bundles/jqueryval")
              .Include("~/Scripts/jquery.unobtrusive*",
                        "~/Scripts/jquery.validate*"));
    BundleTable.Bundles.Add(jsValidationBundle);
}

Both StyleBundle and ScriptBundle take url of the bundled file as a constructor argument and use extension method .Include to add files. You can also use wildcard characters such as * in the include array. If you want to add the entire folder, use IncludeDirectory extension.

One thing to note, is what version of the System.Web.Optimization you have. The older version that came with the MVC4 beta used AddFile() syntax to add files to the bundles. However, if you install VS 2012RC you get a newer version of the DLL, which is a bit neater and uses the syntax shown above.

Rendering Helpers

The library also comes with two awesome helpers. When you develop locally, you want to have all the bundling setup, but you don’t want the bundling and minification to happen – it’s much easier to debug. The System.Web.Optimization has two helpers that address exactly that issue.

  <head>

        ... other content
        @Styles.Render("~/Content/themes/base/css", "~/Content/css")
        @Scripts.Render("~/bundles/jqueryval")
  </head>

When you run the debug setting in the compilation element in your web.config as false, the Styles and Scripts helpers will render the bundled files. However, settings debug=”true” will render them unbundled. Pretty cool!

<system.web>

    .....
    <compilation debug="false" targetFramework="4.5" />
    ....
</system.web>

And that’s not everything, the minified files will also have cache busting string attached based on the files in the bundles.

<link href="/Content/themes/base/css?v=UM624qf1uFt8dYtiIV9PCmYhsyeewBIwY4Ob0i8OdW81" rel="stylesheet" type="text/css" />



ASP.NET 4.5 Hosting - ASPHostPortal :: Difference .NET Client Profile and .NET Framework

clock April 19, 2013 12:55 by author Jervis

.NET Client Profile is supported by .NET Ver. 3.5 and 4.0. It is designed for client applications like Windows Forms. Client Profile version of .NET Framework is lightweight subset of Framework. This enables quicker deployment and small installation packages.

Web Application doesn't support Client Profile version of the Framework.

Microsoft has removed Client Profile from latest version of .NET Framework 4.5 and hence with .NET 4.5 there is no Client Profile as shown in the image below.

 

 



ASP.NET 4.,5 Hosting - ASPHostPortal.com :: Websockets with ASP.Net 4.5 and Visual Studio 2012

clock April 11, 2013 12:11 by author Ben

Web applications are becoming increasingly sophisticated and it is common to need to communicate with various services. There are a number of options to accomplish this task with probably the most popular being to continually poll a server with XHR requests. Other alternatives exist that delay disconnections. These can be tricky to implement and don’t scale well (sometimes worse than polling as they keep a connection open) so aren’t used as much.

 

HTTP isn’t really an ideal protocol for performing frequent requests as:

  • It’s not optimized for speed
  • It utilizes a lot of bandwidth for every request with various headers etc sent with every request
  • To keep an application up to date many requests must be sent
  • Provides limited cross domain support
  • Firewalls & proxys sometimes buffer streaming/long polling solutions increasing latency
  • Long polling & streaming solutions are not very scalable

WebSockets are a new technology that attempts to resolve some of these limitations by:

  • Sending the minimum amount of data necessary
  • Making more efficient usage of bandwidth
  • Providing cross domain support
  • Still operating over HTTP so it can transverse firewalls and proxies
  • Works with some load balancers (TCP l4)
  • Provides support for binary data (note some JavaScript implementations don’t currently support this)

When would web sockets be a suitable protocol for your application?
You might want to consider using web sockets in the following scenarios:

  • Games
  • Real time data
  • Chat applications
  • News tickers

Websockets pitfalls
Websockets is a relatively new protocol that has already undergone a number of versions as various issues are addressed. This is important as support across browsers varies.
At the time of writing Websockets (in some form) can be used by the following browsers (check caniuse.com for the most up to date info):

  • IE10
  • Chrome 13+
  • Firefox 7
  • Safari 5+
  • Opera 11+

Earlier implementations of websockets had some security issues so your connections may work but are not secure (Firefox disabled support in Firefox 4 & 5 for this reason).
The other issue that you may encounter is that some older proxy servers don’t support the http upgrade system that websockets uses to connect so some clients may be unable to connect.

.NET 4.5 Web Socket Support
.NET 4.5 introduces a number of APIs for working with web sockets. If you find you need more control than the ASP.net API’s offers then look into WCF as that has also been updated. Before we begin there are a couple of requirements for using ASP.net web sockets API:

  • Application must be hosted on IIS 8 (available only with some version of Windows 8 – please note currently IIS Express currently does not work)
  • Web Sockets protocol feature installed (IIS option)
  • .net 4.5
  • A compatible browser on the client (IE10 or Chrome will 18 work fine at time of writing)
  • It would help if your Chinese birth animal was the horse

Hello Web Sockets Example!
Ok I am going to assume that you are already working with some version of Windows 8 that has IIS & ASP.net 4.5 installed. The other thing we are going to need to do is make sure IIS has the Web Sockets Protocol feature installed (this is in the add/remove programs bit):

- First create a new empty ASP.net project called WebSockets
- Add the Nuget package Microsoft.Websockets
- Pull down the latest jQuery library and put it in a scripts directory (I am using 1.7.2) – note jQuery isn’t necessary it just saves a bit of tedious event and manipulation code.

Now add a file called index.htm and enter the following code:

<!doctype html>
<head>
<script src="Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
var name = prompt('what is your name?:');
var url = 'ws://' + window.location.hostname + window.location.pathname.replace('index.htm', 'ws.ashx') + '?name=' + name;
alert('Connecting to: ' + url);
ws = new WebSocket(url);
ws.onopen = function () {
$('#messages').prepend('Connected <br/>');
$('#cmdSend').click(function () {
ws.send($('#txtMessage').val());
$('#txtMessage').val('');
});
};
ws.onmessage = function (e) {
$('#chatMessages').prepend(e.data + '<br/>');
};
$('#cmdLeave').click(function () {
ws.close();
});
ws.onclose = function () {
$('#chatMessages').prepend('Closed <br/>');
};
ws.onerror = function (e) {
$('#chatMessages').prepend('Oops something went wront <br/>');
};
});
</script>
</head>
<body>
<input id="txtMessage" />
<input id="cmdSend" type="button" value="Send" />
<input id="cmdLeave" type="button" value="Leave" />
<br />
<div id="chatMessages" />
</body>
</html>


We need to create an http handler so add a new generic handler to the project called ws.ashx and enter the following code:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.Web.WebSockets;
namespace WebSockets
{
public class WSHttpHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
if (context.IsWebSocketRequest)
context.AcceptWebSocketRequest(new TestWebSocketHandler());
}
public bool IsReusable
{
get
{
return false;
}
}
}
}

Finally we need to create something to handle the websocket connection (TestWebSocketHandler that is created in the AcceptWebSocketRequest method).
Create a new class called TestWebSocketHandler and enter the following code:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Web;
using Microsoft.Web.WebSockets;
namespace WebSockets
{
public class TestWebSocketHandler : WebSocketHandler
{
private static WebSocketCollection clients = new WebSocketCollection();
private string name;
public override void OnOpen()
{
this.name = this.WebSocketContext.QueryString["name"];
clients.Add(this);
clients.Broadcast(name + " has connected.");
}
public override void OnMessage(string message)
{
clients.Broadcast(string.Format("{0} said: {1}", name, message));
}
public override void OnClose()
{
clients.Remove(this);


That’s all you need so now compile the project and run it in a compatible browser (IE10 or the latest Chrome will do fine) making sure you are hosting your project from IIS (project properties if you are not).


Once you have run it up you will be prompted to provide a name, then an alert box will indicate the end point of your application (ws://localhost/.. – note the secure https version is wss://).


Now open up a different browser and you should find you can via websockets.



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


 

Corporate Address (Location)

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

Tag cloud

Sign in