How to boost performance of my ASP.NET Website ? Part -II

Dear Friends,
As we have shared earlier how to optimize image (part1) to improve site performance to continue with that topic. I have going to share one more useful topic how to minimize the CSS & JS used in your project.
If you remember Microsoft Ajax minifier (AjaxMinifier) which I have shared earlier in my post we can utilize that tool to

minimize size of the JS & CSS.

So earlier I have explained how to use command prompt to minimize the CSS & JS.
Today I am going to share how to minimize the all the JS & CSS in your project while doing rebuild it.
So here we go just follow below steps.
1)    Go to web solution and unload it  as show in below fig

Boost perfromance of website
2)    Once you have unload the project you will get below screen

Edit project file
3)    Edit the unload project file

Add minifier in project file
4)    Your file will be open in  IDE now add the below lines in project files

<Import Project="$(MSBuildExtensionsPath)\Microsoft\MicrosoftAjax\ajaxmin.tasks" />
<Target Name="AfterBuild">
<ItemGroup>
<JS Include="**\*.js" Exclude="**\*.min.js;" />
</ItemGroup>
<ItemGroup>
<CSS Include="**\*.css" Exclude="**\*.min.css" />
</ItemGroup>
<AjaxMin JsSourceFiles="@(JS)" JsSourceExtensionPattern="\.js$" JsTargetExtension=".min.js" CssSourceFiles="@(CSS)" CssSourceExtensionPattern="\.css$" CssTargetExtension=".min.css" />
</Target>


5)    Now reload the project and build the project. Now refresh the solution and click on show all files. You will some extra files for JavaScript (JS) & CSS file which have same name  and “min” word added in the file.
Like suppose earlier you have Site.css then now you will find site.min.css also.

minimized css & JS

So it is clear now.

Now we can use this compress “minimized” CSS or JS file.
In this way we can use minimized CSS & JS improve the website performance.

So enjoy the New Year with fast performance of the site.
Happy New Year
Thanks & Best Regards,
Rajat Jaiswal

Advertisements

How to boost performance of my ASP.NET Website ?

Dear Friends,

Why my website is slow?

I know this question come in your mind several times.  So I will try to help in boosting performance of your website with sharing some of the utility which helped me hope it will help you also.
As a developer I know the first basic problem is image optimization. So let us fix the image optimization issue first.  To resolve we are going to use image optimization extension.

To download it goes to Extension manager (Tool –> Extension Manager) and search image optimization. You will get following options as shown in below screen

ImageOptimizationExt

Now install the image optimization. It will ask to restart the visual studio. Now just right click the image folder of the project.  You will get image optimization menu as shown in below fig.

optimizationOption

When you run it you will find that the image in that particular folder is optimized and as a output you will get following screen.

output_of_Image_Optimization

As we already know if the size of the page content over the network is less then it will render fast on client machine. So image optimization help in reducing the network size.
I hope you like this post and it may helpful to you either today or may be in future.
I am going to share some more tips related this topic so stay connected
Enjoy.
Thanks & Best Regards,
Rajat jaiswal

“dynamic” new feature in .NET 4.0 , How to use it ?

Dear Friends,
VS 2010 introduce a new variable type which is dynamic.
By the name it is clear that it will have dynamic property means what will be the data type will be decide at run time.
Suppose if I declare dynamic Name = “rajat”

Then Name variable considered as a string variable

Simillarly dynamic Age = 21

Then Age variable is considered as integer.

To understand it more lets follow the example below.

I have declared a test variable which is dynamic type and on each line I assign a different value to the variable as shown in below fig.

dynamic Variable Example

When you run this set of statements you will find following result.

dynamic Variable Type Result

The first variable assignment is considered as integer, the second variable assignment is considered as a string and after last value which is date time variable considered as datatime variable.

So we have seen at each assignment of the value the nature of variable is also changed which is so dynamic that’s why the name it is called dynamic variable type. It Means it bypass compiler time checking.

I hope it give some hit how to use dynamic and where we can use it.

Thanks & best regards,
Rajat Jaiswal

How to Convert current date time different time zone (EST/PST/CST) in ASP.NET (C#) ?

Dear All,
Sometimes your application demands to covert date time in particular time zone.
.NET provided TimeZoneInfo class which help us in converting time in particular time zone.
Steps to utilize this is as follow
1) Convert time in any time zone firstly use UTC time.
2) Use TimeZoneInfo class to convert time zone from UTL to particular time

Below are some examples to utilize this

1) Convert time zone to EST (Eastern Standard Time)
DateTime EstDateTime = DateTime.UtcNow;
EstDateTime= TimeZoneInfo.ConvertTimeFromUtc(EstDateTime, TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"));

2) Convert time zone to PST (Pacific Standard time)
DateTime PSTDateTime = DateTime.UtcNow;
PSTDateTime= TimeZoneInfo.ConvertTimeFromUtc(PSTDateTime, TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time"));

3) Convert time zone to Central Standard Time
DateTime CSTDateTime = DateTime.UtcNow;
CSTDateTime= TimeZoneInfo.ConvertTimeFromUtc(CSTDateTime, TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time "));

4) Convert time zone to GMT Standard Time
DateTime GMTDateTime = DateTime.UtcNow;
CSTDateTime= TimeZoneInfo.ConvertTimeFromUtc(CSTDateTime, TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time"));

I hope this will helpful to you also.

Thanks & Best Regards,
Rajat Jaiswal

How to remove scroll bar from Fancybox when using Iframe?

Dear All,
Suppose you are using JQUERY  FancyBox  popup one of the best popup and showing iframe in it but you are facing issue of scrollbar. You want to avoid scrollbar from fancybox then you have to do following things and I hope it will resolve your problem too.
So here is the solution 
$(document).ready(function () {   
         $(".fancybox").fancybox({             
   'titleShow': false,               
'autoscale': false,               
'autoDimensions': false         
   });      
  });

And in CSS you have to do following things
.fancybox-type-iframe .fancybox-inner {

overflow:hidden !important ;
height:500px !important;
}

It resolved my problem I hope it will resolve your problem too.

Thanks & Best Regards,
Rajat Jaiswal

How to resolve “HTTP Error 500.19 – internal server error” for ASP.NET site ?

Dear All,
Sometimes it may happened that you are trying to configure a website (Asp.net) on a machine and you will find the error

“HTTP Error 500.19 – internal server error”
  “The requested page cannot be accessed because the related configuration data for the page is invalid”

HTTPError500.19
So here are some basic tips which you should follow and hope everything will work fine after this.
1)    Re check the IIS installation whether the IIS installed properly or not for this go to control panel and click on windows Features and check whether IIS application development features installed or not as shown in below fig.
If not installed the install it and re check the website.
iissetings
2)    Once you have checked everything is installed file but still the site is not working then try to assign proper application pool for application (Default Application pool or default 4.0 application pool etc.) and check it.
3)    If still the site is not working then try to give proper permission to website folder. Give proper permission for IIS_USER or everyone.
This things helped me, I hope this will resolve your issue.
Enjoy Configuration.
Thanks & Best Regards,
Rajat Jaiswal

How to get distinct entities from a collection using LINQ ?

Dear All,
Many times you have problems like you have a collection which has duplicate entries now you want a LINQ operation which provides you distinct collection as result.
Let start with following example
I have one class which is Contact as declared follow

public class Contacts        {
public string FirstName { get; set; }
public string LastName { get; set; }
public string Phone { get; set; }
}

This class has FirstName, LastName & mobile property.
Now suppose you have following collection

List<Contacts> oContacts = new List<Contacts>() {
new Contacts{ FirstName ="Rajat", LastName="Jaiswal", Phone="123"},
new Contacts{ FirstName ="Sparsh", LastName="Anchaliya", Phone="223"},
new Contacts{ FirstName ="Ajit", LastName="Bagora", Phone="423"},
new Contacts{ FirstName ="Arjun", LastName="Singh", Phone="523"},
new Contacts{ FirstName ="Piyush", LastName="Redwal", Phone="623"},
new Contacts{ FirstName ="Rajat", LastName="Jaiswal", Phone="123"},
new Contacts{ FirstName ="Sparsh", LastName="Anchaliya", Phone="223"},
new Contacts{ FirstName ="Ajit", LastName="Bagora", Phone="423"},
new Contacts{FirstName ="Ajit", LastName="Bagora", Phone="423"},
new Contacts{ FirstName ="Rajat", LastName="Jaiswal", Phone="123"},
new Contacts{ FirstName ="Piyush", LastName="Redwal", Phone="623"},
new Contacts{ FirstName ="Piyush", LastName="Redwal", Phone="623"},
new Contacts{ FirstName ="Arjun", LastName="Singh", Phone="523"},
};

Now the above collection having total 13 contact entities but there is only 5 records which are distinct.
Now you want a LINQ operation which provides only 5 records which are distinct.
To get this we will write following LINQ


List<Contacts> lstContact = oContacts.GroupBy(x => x.FirstName + x.LastName + x.Phone).Select(y => y.First()).ToList<Contacts>() ;

The above LINQ operation will provide you distinct entities.
The logic behind the above statement is very simple we just group by all the columns first and selected first records from that group collection for each group.

I hope you also enjoyed with above LINQ operation as I enjoyed.

Keep Learning
Rajat Jaiswal

How to remove unwanted space from require field validator ?

Dear friends,
It may be possible that you know it but here I am going to share one simple tip to remove unwanted space occupied by required field validator control.
Just consider below login screen. On this field we have kept require field validator control.

 

withoutDynamic
The require field is just below the text box and it took unnecessary space.

validation
To resolve this issue you just need to change a simple property which is Display=”Dynamic” of require field validator.

Once you have changed the property to display dynamic the unwanted space automatically removed and it will consume only when validation failed.
The new screen will look like as below

After_dynamic_Use

So use display “Dynamic” property in required field validator.

Thanks & Best Regards,
Rajat Jaiswal