Friday, April 17, 2020

How to loop through HTML table columns?

To loop through each table columns follow the below code.

    <link rel="stylesheet" href=""
        integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <div class="container">
        <div class="col-12">
            <table class="table table-bordered">
    <script src=""
        integrity="sha256-xNzN2a4ltkB44Mc/Jz3pT4iU1cmeR0FkXs4pru/JxaQ=" crossorigin="anonymous"></script>

        var nrow = $("table")[0].rows.length;
        var ncol = $("table")[0].rows[0].cells.length;

        for (let c = 0c < ncolc++) {

            for (let r = 0r < nrowr++) {




How to run HTML file from VSCode?

We can easily run the HTML file by using an extention called Live Server by Ritwick Dey.

Note: To run the file it must be inside a directory or else it wont run. 

Sunday, February 2, 2020

Disable the browser back button

Use this script to disable the browser back button once the user has logged out. So that even if he tries to click the back button and go back to the previous page he will not be able to go.

    history.pushState(null, null, location.href);
    window.onpopstate = function () {

Forms Authentication in MVC


@using (Html.BeginForm("index","home",FormMethod.Post))

    <span>Enter Name</span>
    <input type="text" name="name"  required />

    <input type="submit"  value="Submit" />



        using System.Web.Security;

        public ActionResult Index(FormCollection formCollection)

            if (ModelState.IsValid)
                  var authTicket = new FormsAuthenticationTicket(
                    1,// version
                    formCollection["name"].ToString(), // user name
                    DateTime.Now, // created
                    DateTime.Now.AddMinutes(20), // expires
                    false// persistent?
                    "User"  // can be used to store roles

                string encryptedTicket = FormsAuthentication.Encrypt(authTicket);

                var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);


                return RedirectToAction("about");

                return View();

 [Authorize(Roles ="User")]
        public ActionResult About()
            ViewBag.Message = "Your application description page.";

            return View();

        public ActionResult logout()

            return RedirectToAction("index");      

Inside the Global.asax.cs

using System.Security.Principal;
using System.Web.Security;

        protected void Application_AuthenticateRequest(Object sender, EventArgs e)
            HttpCookie authCookie = Context.Request.Cookies[FormsAuthentication.FormsCookieName];

            if (authCookie == null || authCookie.Value == "")

            FormsAuthenticationTicket authTicket;

                authTicket = FormsAuthentication.Decrypt(authCookie.Value);

            // retrieve roles from UserData
            string[] roles = authTicket.UserData.Split(';');

            if (Context.User != null)
                Context.User = new GenericPrincipal(Context.User.Identity, roles);


Inside the web.config

  <authentication mode="Forms" >
    <forms defaultUrl="home/index" loginUrl="home/index"  protection="All"></forms>

    <allow users="*"/>
    <deny users="?"/>

Saturday, December 7, 2019

Deploy Django application on XAMPP apache Server (Windows)

Below are the steps to deploy the Django application on XAMPP apache server.

Assuming that you have already downloaded and installed the following.

  • After copying the file from the folder rename it with and paste the file where the XAMPP server is installed on your system inside the modules.

  • Make change in the httpd.conf file

  • Add the below line in httpd.conf

  • Create a Django project inside the htdocs folder.

  • After completion of the project when ready to deploy once again open the httpd.conf and add few more lines of code.

  • After add the above lines of code then restart the system and run the XAMPP server to check 

Sunday, November 17, 2019

Excluding fields in MongoDB using

using MongoDB.Bson;
using MongoDB.Driver;                             
static MongoClient client = new MongoClient("mongodb://localhost:27017"); //Set the connection string

static IMongoDatabase db = client.GetDatabase("test"); //Database name

public void Exclude()
   IMongoCollection<BsonDocument> collection = db.GetCollection<BsonDocument>("user");

   var filter = Builders<BsonDocument>.Filter.Empty;   

 // uncomment the below two lines to exclude the required things

// var project = Builders<BsonDocument>.Projection.Exclude("_id"); //replace the field which you want to exclude in place of _id and it must match the field name in the MongoDB document

//var res = collection.Find<BsonDocument>(filter).Project(project).ToList();

    var res = collection.Find(filter).ToList(); //Comment this after un commenting the above two line


Before excluding _id field


How to loop through HTML table columns?

To loop through each table columns follow the below code. <html> <head>      <link   rel = "stylesheet"   ...