Friday, January 9, 2015

Best clash of clans strategy to save gold and elixir from attackers!!

Everyone has their own strategy to get more and more gold and elixir in Clash of clan. I developed my own strategy to save gold and elixir from attackers I save my hard earned gold and elixir from raider by adapting to a specific village layout. This strategy has two parts.

First part is to put your gold, elixir and dark elixir storage in the middle of the village. But make sure there should be a gap between them otherwise the raider can easily loot it using lighting spell. Better to put some defence unit in between storages. Create a village layout to provide best protection to your storages and if possible put your mines inside the wall so that the raider has to do hard work to loot even single penny from your storages.

Now come to second part. Place your town hall in one corner of the village map. So that raider can easily destroy the town hall and can win the attack. If you want you can put some defence unit like hidden tesla and traps near to the town hall so the unprepared raider will get some surprise. There are many attackers who attack only for trophy. They only look for villages where the town hall is easily accessible so that they can win the attack and gain few trophies. You will not lose more than 10 trophies if the attacker destroy only town hall. You will lose near about 1000 god and elixir, and in return you will get 12 hours of protection. I hope you will not better deal from this!!



You can maintain your trophies by attacking other villages or to get it easily simply place your town hall in the centre of the village for few days when you have less gold and elixir in your storages. Best way to do this by creating two layouts and use them as per your need. I hope you like my strategy. Please give your comments if you need any help in the game or you have any good idea to share. All the best for your village and enjoy playing Clash of clans!! 

Monday, December 29, 2014

C#.NET server side function to get the browser information

There are many scenario while you need to get the browser type and it's version in .net. Best example is exception handling. This function will make your task easy to get the browser type with it's version number.

function GetBrowser(){
 var browser="";
 var version=0;

 if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){
  version=new Number(RegExp.$1);
  browser="FireFox";} else {

  if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){
   version=new Number(RegExp.$1);
   browser="Internet Explorer";} else {

   if (/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent)){
    version=new Number(RegExp.$1);
    browser="Opera";} else {

    if (/Chrome[\/\s](\d+\.\d+)/.test(navigator.userAgent)){
     version=new Number(RegExp.$1);
     if (version==18) {version=3; browser="Maxthon";} else {browser="Google Chrome"}} else {version=0; browser="Undetermined";}
 }}}
 return browser+' '+version;}

Wednesday, December 24, 2014

How to handle page not found exception in MVC?

There are many way to handle page not found exception. Here is I am describing a simple way to handle this. It just captures the http error status code 404 and redirects the user to Page not found view.
Create a simple view to show page not found message. I suggest to create this “PageNotFound.cshtml” view in the shared folder. See the below code of the view.

<div class="row-fluid visible-on" style="padding-top:70px;">
    <div class="col-lg-3 col-md-3 col-sm-3"></div>
    <div class="col-lg-6 col-md-6 col-sm-6">       
        <div class="well">
            <h4>
                Page Not Found
            </h4><hr />
            <p>
                The requested page does not exist.<br /><br />

Please try correct URL or @Html.ActionLink("click here""Login""Account", routeValues: null, htmlAttributes: new { id = "loginLink" }) to go to login screen.
            </p>
        </div>
    </div>
    <div class="col-lg-3 col-md-3 col-sm-3 visible-lg"></div>
</div>

We need to change the web.config file to redirect the control to ErrorController in case of exception where the response status code is 404.

Here is the code to add in web.config file.

 <customErrors mode="On">     
      <error statusCode="404" redirect="Error/PageNotFound"/>
</customErrors>

Let’s go through the final step to complete the exception handling. We need to create a controller with name “ErrorController” and add “PageNotFound” action inside the controller class. Here is the full code snippet.

public class ErrorController : Controller
    {
        //Redirect to Page not found page in case of 404 http status code.
        // GET: PageNotFound
        public ActionResult PageNotFound()
        {
            Response.StatusCode = 404;
            return View("PageNotFound");
        }
    }


 That’s it. Is not it easy? Now if someone tries to enter wrong URL inside of showing default browser page not found page. It will redirect to the custom view we have created. This is the simplest way to hand page not found exception. If you want to implement a sophisticated exception handing code then please refer the below links for few good references. 

My first blog

This is my first blog post. I have created this blog to share knowledge i have learned from high and low time of my life. It may help others and save their time. when ever someone get benefit from my blog. I will feel like i get paid for the time i spent on writing this blog.

Hope i will write some good blogs!! Thanks