How to display and customize the reCAPTCHA v2 widget on your asp.net web page ?

1. Register reCAPTCHA API Key:

Get your Site Key and Secret Key.

Go to the Google reCAPTCHA Admin Console and register your site.

2. Client-Side (Frontend) Integration:

Add the following code to the aspx page where you want the reCAPTCHA widget to appear:

htmlCopy code<form id="form1" runat="server">
    https://www.google.com/recaptcha/api.js
    <div class="g-recaptcha" data-sitekey="Your-Site-Key"></div>
    <input type="submit" value="Submit" />
</form>
  • Replace Your-Site-Key with your actual Site Key.
  • This will display the default Google reCAPTCHA v2 widget.

3. Server-Side Validation:

In your code-behind, validate the user’s response by sending a POST request to Google’s reCAPTCHA API with the user’s response token and your Secret Key.

Here’s an example in C#:

csharpCopy codeusing System.Net;
using System.IO;
using Newtonsoft.Json;

protected void Page_Load(object sender, EventArgs e)
{
    if (IsPostBack)
    {
        string captchaResponse = Request["g-recaptcha-response"];
        var result = ValidateCaptcha(captchaResponse);
        if (result.success)
        {
            // Proceed with form processing
        }
        else
        {
            // Handle failed validation
        }
    }
}

public class ReCaptchaResponse
{
    public bool success { get; set; }
    public string challenge_ts { get; set; }
    public string hostname { get; set; }
}

private ReCaptchaResponse ValidateCaptcha(string response)
{
    var secretKey = "Your-Secret-Key";
    var requestUri = $"https://www.google.com/recaptcha/api/siteverify?secret={secretKey}&response={response}";

    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(requestUri);
    req.Method = "POST";

    using (WebResponse resp = req.GetResponse())
    {
        using (StreamReader sr = new StreamReader(resp.GetResponseStream()))
        {
            string jsonResponse = sr.ReadToEnd();
            return JsonConvert.DeserializeObject<ReCaptchaResponse>(jsonResponse);
        }
    }
}
  • Replace Your-Secret-Key with your actual Secret Key.

Summary:

  1. Add the widget to your page by using Google’s g-recaptcha element.
  2. Validate the response server-side by making a POST request to Google’s reCAPTCHA API.
  3. Customize the widget using data-* attributes.
  4. Optionally, install a NuGet package for ASP.NET to help with validation.
  5. For example – refer below you tube video from Sudhanshu Jain

How to fix current source code is different from the version built debugger not hitting in visual studio 2022?

Make sure that your project is set to Build – Optimize code (make it unchecked) and in the advanced build settings option Output- Debugging information to Full.

Right click on your project file and click properties option. – Do check the above mentioned is correctly added and if this will not helps to fix the issue, read below article and DIY.

The error “The current source code is different from the version built” in Visual Studio 2022 typically indicates a mismatch between the source code you’re viewing and the executable code that Visual Studio is running or debugging. Here are steps to resolve this issue:

1. Clean and Rebuild the Solution

  1. Clean the Solution:
    • Go to Build > Clean Solution.
  2. Rebuild the Solution:
    • Go to Build > Rebuild Solution.

2. Delete the bin and obj Folders

  1. Locate the bin and obj folders:
    • These are usually found in the project’s directory.
  2. Delete these folders.
  3. Rebuild the solution:
    • Go to Build > Rebuild Solution.

3. Restart Visual Studio

  1. Close Visual Studio.
  2. Reopen Visual Studio.
  3. Rebuild the solution:
    • Go to Build > Rebuild Solution.

4. Ensure Symbols are Loaded

  1. Go to Debug > Windows > Modules.
  2. Ensure that the symbols for your modules are loaded.
  3. Right-click on the module and select Load Symbols if they are not loaded.

5. Check Configuration and Platform

  1. Ensure you are building and debugging the same configuration (e.g., Debug/Release).
    • You can check this in the toolbar dropdowns.
  2. Ensure the same platform is selected (e.g., x86/x64).

6. Check for Conditional Compilation

  1. Check if there are any conditional compilation symbols (e.g., #if DEBUG) that might be causing differences between the code you see and what is built.
  2. Ensure you are running the correct build configuration.

7. Ensure Source Code Path is Correct

  1. Go to Debug > Options > Debugging > Symbols.
  2. Check the path to the source code files.
  3. Ensure the correct path is set and there are no outdated or incorrect paths.

8. Verify Source Control Sync

  1. If using source control (e.g., Git), ensure your local files are up to date and match the branch you are building.

9. Check for Multiple Projects/References

  1. Ensure that all projects and references within your solution are built.
  2. Right-click on the solution in the Solution Explorer and select Project Dependencies.
  3. Ensure that all dependencies are correctly set.

10. Use the Source Server

  1. If using a source server, ensure it is correctly set up.
    • Go to Debug > Options > Debugging > General.
    • Check Enable source server support.

Gmail requires all senders to authenticate with either SPF or DKIM, error while sending mails from Ionos web mail server.

If you are having trouble sending emails to Gmail accounts, it may be that the SPF record for IONOS SPF is missing for some reason. In this case, follow the steps below to add SPF to your domain.

Select the IONOS SPF(TXT) and save the DNS record. Please note that it may take up to 48 hours for this change to propagate globally and for the SPF record to take effect.

https://www.ionos.co.uk/help/domains/configuring-mail-servers-and-other-related-records/using-ionos-spf-to-improve-email-delivery/

How to Scaffold -DbContext and table classes in different project ?

I had my EntityFramework model classes in a separate project. In order to write the models there, I just used the following command:

Scaffold-DbContext "Server=[ServerName];Database=[DatabaseName];Trsted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -Project "[Project Name]" -Force 

Scaffold-DbContext “Server=SERVER-2016;Database=GWV_Test; encrypt=false; User Id = sa; Password=Password1;” Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Project “Core.DTO” -Context GwvTestContext -Force

The remote server returned an unexpected response: (413) Request Entity Too Large in WCF

<bindings>
  <wsHttpBinding>
  </wsHttpBinding>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IeNett" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false" bypassProxyOnLocal="false" maxBufferPoolSize="666665536" maxReceivedMessageSize="666665536" useDefaultWebProxy="true" />
    <binding name="BasicHttpBinding_Ipricingservice" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false" bypassProxyOnLocal="false" maxBufferPoolSize="666665536" maxReceivedMessageSize="666665536" useDefaultWebProxy="true" />
    <binding name="BasicHttpBinding_ICommonService" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false" bypassProxyOnLocal="false" maxBufferPoolSize="666665536" maxReceivedMessageSize="666665536" useDefaultWebProxy="true" />
    <binding name="BasicHttpBinding_ITransfer" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false" bypassProxyOnLocal="false" maxBufferPoolSize="666665536" maxReceivedMessageSize="666665536" useDefaultWebProxy="true" />
    <binding name="BasicHttpBinding_ITransfer1" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false" bypassProxyOnLocal="false" maxBufferPoolSize="666665536" maxReceivedMessageSize="666665536" useDefaultWebProxy="true" />
    <binding name="BasicHttpBinding_IAirService" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false" bypassProxyOnLocal="false" maxBufferPoolSize="666665536" maxReceivedMessageSize="666665536" useDefaultWebProxy="true" />
    <binding name="BasicHttpBinding_IB2BTMPService" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false" bypassProxyOnLocal="false" maxBufferPoolSize="666665536" maxReceivedMessageSize="666665536" useDefaultWebProxy="true" />
    <binding name="BasicHttpBinding_IHotel" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false" bypassProxyOnLocal="false" maxBufferPoolSize="666665536" maxReceivedMessageSize="666665536" useDefaultWebProxy="true" />
    <binding name="BasicHttpBinding_ITravelInsurance" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false" bypassProxyOnLocal="false" maxBufferPoolSize="666665536" maxReceivedMessageSize="666665536" useDefaultWebProxy="true" />
  </basicHttpBinding>
</bindings>

How to solve “You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column. To disable safe mode, toggle the option in Preferences -> SQL Editor and reconnect”.

While altering one procedure in my sql database i got above mentioned error. One of my college Mr.AjayGhosh who is an encyclopedia in MySQL database helped me to solve this issue.

SET SQL_SAFE_UPDATES = 0;
DELETE FROM temp_todo WHERE id NOT IN (SELECT idRetain FROM temp_Distinct);
SET SQL_SAFE_UPDATES = 1;

How to create database user and assign database visibilty in SQL Server?

Today my friend Ajmal requested a help to configure database user with permission to access only one database associated with that user.

Arun.T.K a young and dynamic database administrator who is an encyclopedia in MsSqlServer really helped me to achieve this task

Making a SQL Server database visible to only database owner and sysadmin role. This requires you to modify the database owner using store procedure, but likely not the one you expect.

USE [FlamingoB2C]
GO
CREATE LOGIN FlamingoUser with Password=’U$er_A@1234′ ( This will login user in database)
GO
USE [FlamingoB2C]
GO
CREATE USER FlamingoUser for login FlamingoUser; (This will create user for selected Login)
GO
USE [FlamingoB2C]
GO
EXEC sp_addrolemember ‘db_owner’, ‘FlamingoUser’ ( This will add this user in role database owner)
GO
USE [FlamingoB2C]
GO
EXEC sp_changedbowner [FlamingoUser] ( This will change the user to selected database owner)

Before running the above step we should remove the user from Security tab in specific database.

For disable unwanted database for specific user, we need to right click on the Sql server and go to properties. From there we need to select permissions. Deny permission for View any database.

Git PowerShell command line interface

There are a lot of different ways to use Git. There are the original command-line tools, and there are many graphical user interfaces of varying capabilities. 

Commands for different functions

git status –> This will get the details of files need to check in

git add . –> This will add the files

git commit -m “change set name here”

git checkout development branch

git fetch

git pull

git push -u origin BRANCH NAME”bugfix/WHSV2-2018-Return-to-work-Publish-Regiter-is-Not-working”

git checkout to your local branch”bugfix/WHSV2-2018-Return-to-work-Publish-Regiter-is-Not-working”

git merge develop

git checkout -b bugfix/WHSV2-2025-RTW-Register-Return-Date-is-showing-incorrect-Date( For Create new Branch)