Git remote: HTTP Basic: Access denied and fatal Authentication

Git remote: HTTP Basic: Access denied and fatal Authentication



Sometimes, I am facing issue with Git and getting error that - "Git remote: HTTP Basic: Access denied and fatal Authentication".

Problem occurs while I change my password of Git. 

So, we need to update git password in Windows system.


Solution 1

Go to Windows Credential Manager (press Windows Key and type 'credential') to edit the git entry under Windows Credentials. Replace old password with the new one.

Solution 2

1. Run below command from cmd

git config --system --unset credential.helper

And when I execute the above command, I got another error

error: could not lock config file C:\Program Files\Git\mingw64/etc/gitconfig: Permission denied

2. And then I removed gitconfig file from C:\Program Files\Git\mingw64/etc/ location

3. After that use git command like git pull or git push, it asked me for username and password. applying valid username and password and git command working.


Hope this will help you and save your time.

Enjoy !!!

:)

Use Local internet after VPN connected

Use Local internet after VPN connected


 I faced issue with my local internet connection after I connected VPN. Then I my friend helped me to resolve issue with below steps. 

After followed below steps, yes I can use my internet.

Steps

1. Press the Windows logo key+R to open the Run box.
2. Type ncpa.cpl in the Run box, and then press Enter to open Network Connections.
3. Right-click the VPN connection, and then click Properties.
4. Click the Networking tab in the VPN connection properties dialog box, select Internet Protocol Version 6 (TCP/IPv6), and then click Properties.
5. Click Advanced… in the Protocol properties box.
6. Click the IP Settings tab in the Advanced TCP/IP Settings box.
7. To disable the default gateway, clear the Use default gateway on remote network check box. Or, to enable the default gateway, 8. select the Use default gateway on remote network check box.
9. Click OK to close the Advanced TCP/IP Settings dialog box.
10. Click OK to close the Protocol properties dialog box.
11. Select Internet Protocol Version 4 (TCP/IPv4), click Properties, and then repeat step 5 through step 9 to change the default gateway setting for IPv4.
12. Click OK to close the VPN connection properties dialog box. 


Hope this will help you and save your time.

Enjoy !!!

:)

jquery datatable global search on keypress of enter key instead of any key keypress

datatable global search on keypress of enter key instead of any key keypress


We can use search feature by pressing "enter key" instead of key press search...

We need to add below code,


$('#myTable_filter input').unbind();
    $('#myTable_filter input').bind('keyup'function (e) {
        if (e.keyCode == 13) {
            table.search(this.value).draw();
        }
    });

Full code of bind datatable

var table = "";
var apisitename = 'http://localhost/DemoApp/api/'; 

$(document).ready(function () {
     
    table = $("#myTable").DataTable({
        "processing": true,
        "serverSide": true,
        "searching": true,
        "ordering": true,
        "paging": true,
        "responsive": true,
        "ajax": {
            "url": apisitename + "CountriesList",
            "type": "get",
            "datatype": "json" 
        },
        "columns": [
            { "data": "Name", "name": "Name"},
            {
                data: null,
                orderable: false,
                width: 100,
                render: function (data, type, row) { 
                    return "<a href='country/detail/?id=" + data.ID + "' class='btn btn-primary btn-small-x fa fa-search'></a>";
                }
            }
        ]
    });

    $('#myTable_filter input').unbind();
    $('#myTable_filter input').bind('keyup', function (e) {
        if (e.keyCode == 13) {
            table.search(this.value).draw();
        }
    });

});


HTML 

 <table id="myTable" class="display responsive nowrap" cellspacing="0" width="100%">
                <thead>
                    <tr>
                        <th>Country Name</th>
                        <th>Action</th>
                    </tr>
                </thead>
            </table>

Hope this will help you and save your time.

Enjoy !!!

:)

URL QueryString with Encryption & Decryption

URL QueryString with Encryption & Decryption

For the security concern we have to pass querystring value in encrypted mode,  and while we retrieve querystring value we need to decrypt it and use it.

Here, I mentioned..


  1. Plain text encryption
  2. Decryption of encrypted text
  3. URL encode (System.Web.HttpUtility.UrlEncode)
  4. URL decode (System.Web.HttpUtility.UrlDecode)

Here, I have mentioned URL querystring encryption and decryption...

Encryption

protected void Submit(object sender, EventArgs e)
    {
  string username = "anrorathod";
  string userid = "2279";
        string uname = HttpUtility.UrlEncode(Encrypt(username));
        string uid = HttpUtility.UrlEncode(Encrypt(userid));
        Response.Redirect(string.Format("~/newpagename.aspx?name={0}&id={1}", uname, uid));
    }

    private string Encrypt(string textToEncrypt)
    {
        string EncryptionKey = "Writeyourkeyhere-Youcanwriteanything";
        byte[] clearBytes = Encoding.Unicode.GetBytes(textToEncrypt);
        using (Aes encryptor = Aes.Create())
        {
            Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });
            encryptor.Key = pdb.GetBytes(32);
            encryptor.IV = pdb.GetBytes(16);
            using (MemoryStream ms = new MemoryStream())
            {
                using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateEncryptor(), CryptoStreamMode.Write))
                {
                    cs.Write(clearBytes, 0, clearBytes.Length);
                    cs.Close();
                }
                textToEncrypt = Convert.ToBase64String(ms.ToArray());
            }
        }
        return textToEncrypt;
    }


Decryption

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
   string username = Decrypt(HttpUtility.UrlDecode(Request.QueryString["name"]));
   string userid = Decrypt(HttpUtility.UrlDecode(Request.QueryString["id"]));
        }
    }

    private string Decrypt(string textToDecrypt)
    {
        string EncryptionKey = "Writeyourkeyhere-Youcanwriteanything";
        textToDecrypt = textToDecrypt.Replace(" ", "+");
        byte[] cipherBytes = Convert.FromBase64String(textToDecrypt);
        using (Aes encryptor = Aes.Create())
        {
            Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });
            encryptor.Key = pdb.GetBytes(32);
            encryptor.IV = pdb.GetBytes(16);
            using (MemoryStream ms = new MemoryStream())
            {
                using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateDecryptor(), CryptoStreamMode.Write))
                {
                    cs.Write(cipherBytes, 0, cipherBytes.Length);
                    cs.Close();
                }
                textToDecrypt = Encoding.Unicode.GetString(ms.ToArray());
            }
        }
        return textToDecrypt;
    }

Hope this will help you and save your time.

Enjoy !!!

:)

Autofac Dependency Injection with Simple Class using MVC Web API

Autofac Dependency Injection with Simple Class using MVC Web API 


Add class library called - Project.Business

Add class - TestSimpleService

public class TestSimpleService
{
 public string GetPing()
 {
  return "simple class called";
 }
}
 


Add WebAPI Project called Project.API

Add nuget packages => Autofac, Autofac.WebApi2 and EntityFramework


Add Controller - TestController

public class TestController : ApiController
{
 TestSimpleService testService;
 public TestController(TestSimpleService _testService)
 {
  testService = _testService;
 }

 [HttpGet]
 [Route("CallSimple")]
 public HttpResponseMessage GetPing()
 {
  var ping = testService.GetPing();
  return Request.CreateResponse(HttpStatusCode.OK, ping);
 }
}
 
 

  

Add class AutofacConfigs.cs

public class AutofacConfigs
{
 public static void Configure()
 {
  var builder = new ContainerBuilder();
  builder.RegisterApiControllers(Assembly.GetExecutingAssembly()); 

  //Add Simple class  mapping
   builder.RegisterType<TestSimpleService>().AsSelf().InstancePerRequest();

  var container = builder.Build();
  var resolver = new AutofacWebApiDependencyResolver(container);
  GlobalConfiguration.Configuration.DependencyResolver = resolver;
 }
}
 

  

register this class application start
protected void Application_Start()
{
AutofacConfigs.Configure();
// ... other configuration

}


Run application

Hope this will help you and save your time.

Enjoy !!!

:)

Autofac Dependency Injection with MVC Web API

Autofac Dependency Injection with MVC Web API

Add Class library called - Project.Data

Add Entity Data Model - .edmx and select your database table and add it in edmx fie (For me I am adding Employee table)

Add Interface name => IEmployeeData

public interface IEmployeeData
  {
   List<Employee> GetEmployees();
  }
 

Add Simple class EmployeeData and inherite interface

public class EmployeeData : IEmployeeData
  {
   public List<Employee> GetEmployees()
   {
    List<Employee> employees;
    using (var db = new DemoEntities())
    {
     employees = db.Employees.ToList();
    }
    return employees;
   }
  }
 

  

Add class library called - Project.Business

Add Inteface - IEmployeeService

public interface IEmployeeService
  {
   List<Employee> GetEmployees();
  }



Add Simple class EmployeeData and inherite interface

public class EmployeeService : IEmployeeService
{
 IEmployeeData employeeData;
 public EmployeeService(IEmployeeData _employeeData)
 {
  employeeData = _employeeData;
 }
 public List<Employee> GetEmployees()
 {
  return employeeData.GetEmployees();
 }
}

  

Add WebAPI Project called Project.API

Add nuget packages => Autofac, Autofac.WebApi2 and EntityFramework

Add ConnectionString in web.config file


Add Controller - EmployeeController

public class EmployeeController : ApiController
    {
        IEmployeeService employeeService;
        public EmployeeController(IEmployeeService _employeeService)
        {
            employeeService = _employeeService;
        }

        [HttpGet]
        [Route("employees")]
        public HttpResponseMessage GetEmployees()
        {
            var employees = employeeService.GetEmployees();
            return Request.CreateResponse(HttpStatusCode.OK, employees);
        }
    }
 

  

Add class AutofacConfigs.cs

public class AutofacConfigs
{
 public static void Configure()
 {
  var builder = new ContainerBuilder();
  builder.RegisterApiControllers(Assembly.GetExecutingAssembly()); 

  //Add Service mapping
  builder.RegisterType<EmployeeService>().As<IEmployeeService>();

  //Add data mapping
  builder.RegisterType<EmployeeData>().As<IEmployeeData>();

  var container = builder.Build();
  var resolver = new AutofacWebApiDependencyResolver(container);
  GlobalConfiguration.Configuration.DependencyResolver = resolver;
 }
}

 

  

register this class application start
protected void Application_Start()
{
AutofacConfigs.Configure();
// ... other configuration

}


Run application

Hope this will help you and save your time.

Enjoy !!!

:)

SQL Server - Cursor example

SQL Server - Cursor example

Sometimes we need to run loop on data, for that we need cursor. We can write our own business logic in cursor loop. 

Cursor is nothing but it is a loop like development code.

Here, I have mentioned cursor syntax with example. I hope you can use cursor easily as per your requirement...
-- Declare field variable
DECLARE @id INT
DECLARE @fname nvarchar(50)
DECLARE @lname nvarchar(50)
DECLARE @email nvarchar(50)

-- Declare Cursor name
DECLARE @curEmployee CURSOR

-- Set Cursor value
SET @curEmployee = CURSOR FOR
 SELECT id, EmailId, Firstname, LastName FROM Employee

OPEN @curEmployee

-- Loop Cursor
FETCH NEXT
 FROM @curEmployee INTO @id, @email, @fname, @lname
 WHILE @@FETCH_STATUS = 0
 BEGIN
  PRINT convert(nvarchar(10) , @id) + ' - ' + @fname + ' ' + @lname + ' -- ' + @email
  -- TODO
  -- Do your process 
 FETCH NEXT
 FROM @curEmployee INTO @id, @email, @fname, @lname
END

-- Close and deallocate Cursor
CLOSE @curEmployee
DEALLOCATE @curEmployee
 

 


Hope this will help you and save your time.

Enjoy !!!

:)