Monday, September 30, 2013

Bundling in visual studio 2012 for web optimization

As we know now days web applications or site are providing more and more features and due to that we have include lots of JavaScript and CSS files in our web application.So once we load site then we will have all the JavaScript  js files and CSS files loaded in the browsers and If you have lots of JavaScript files then its consumes lots of time when browser request them.
Following images show the same situation over there.

Bundling feature in Visual Studio 2012 - Visual Studio 2012 feature series

Here you can see total 25 files loaded into the system and it's almost more than 1MB of total size. As we need to have our web application of site very responsive and need to have high performance application/site, this will be a performance bottleneck to our site. In situation like this, the bundling feature of Visual Studio 2012 and ASP.NET 4.5 comes very handy. With the help of this feature we do optimization there and we can increase performance of our application.


To enable this feature in Visual Studio 2012 we just made debug=”false” in web.config of our application like following.

How to enable bundling in Visual Studio 2012

Now once you enable this feature and run this application in the browser to see your traffic it will have less items like following.

AfterBudnlingenabledinVisualStudio2012

Multiple file upload with asp.net 4.5 and Visual Studio 2012

With ASP.NET 4.5 version Microsoft has enhanced file upload control to support HTML5 multiple attribute. There is a property called ‘AllowedMultiple’ to support that attribute and with that you can easily upload the file. So what we are waiting for!! It’s time to create one example.
On the default.aspx file I have written following.

1
2
<asp:FileUpload ID="multipleFile" runat="server" AllowMultiple="true" />
<asp:Button ID="uploadFile" runat="server" Text="Upload files" onclick="uploadFile_Click"/>

Here you can see that I have given file upload control id as multipleFile and I have set AllowMultiple file to true. I have also taken one button for uploading file.For this example I am going to upload file in images folder. As you can see I have also attached event handler for button’s click event. So it’s time to write server side code for this. Following code is for the server side.

1
2
3
4
5
6
7
8
9
10
11
protected void uploadFile_Click(object sender, EventArgs e)
{
    if (multipleFile.HasFiles)
    {
        foreach(HttpPostedFile uploadedFile in multipleFile.PostedFiles)
        {
            uploadedFile.SaveAs(System.IO.Path.Combine(Server.MapPath("~/Images/"),uploadedFile.FileName));
            Response.Write("File uploaded successfully");
        }
    }
}



Here in the above code you can see that I have checked whether multiple file upload control has multiple files or not and then I have save that in Images folder of web application. Once you run the application in browser it will look like following.

Multiple file upload with asp.net 4.5 and Visual Studio 2012


I have selected two files. Once I have selected and clicked on upload file button it will give message like following.

Multiple file upload with ASP.NET 4.5 and HTML5

As you can see now it has successfully upload file and you can see in windows explorer like following.

Multiple file upload ASP.NET 4.5 and Visual Studio 2012

As you can see it’s very easy to upload multiple file in ASP.NET 4.5. Stay tuned for more. Till then happy programming.

Kubernetes

Prerequisites We assume anyone who wants to understand Kubernetes should have an understating of how the Docker works, how the Docker images...