Aketch  Rachel

Aketch Rachel


How To Send OTP SMS On User Mobile Using ASP.NET C# in 5 simple steps.

How To Send OTP SMS On User Mobile Using ASP.NET C# in 5 simple steps:
Step 1

Create a new website.

Step 2

Create a webform aspx page.

Step 3

Design the webpage like below,

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <form id="form1" runat="server">
        <table style="border:solid;border-width:thin">
            <td><asp:Label ID="lblmobele" runat="server" Text="Enter Mobile Number"></asp:Label></td>
            <td><asp:TextBox ID="txtmobileno" runat="server"></asp:TextBox></td>
                <td><asp:Button ID="btnSendOTP" runat="server" Text="Send OTP" OnClick="btnSendOTP_Click"></asp:Button></td>

      <asp:Label ID="lblMsg" runat="server" Text=""></asp:Label>

Step 4

Added below namespace in .aspx.cs page,

using System.Drawing;
using System.Web.UI.WebControls;
using System.Data;
using System.Web;
using System.Net;
using System.IO;
using System.Web.UI;
using System.Collections.Generic;
using System.Linq;

Step 5

Add the below source code in .aspx.cs page.

// Start OTP Generation function
protected string Generate_otp() {
    char[] charArr = "0123456789".ToCharArray();
    string strrandom = string.Empty;
    Random objran = new Random();
    for (int i = 0; i < 4; i++) {
        //It will not allow Repetation of Characters
        int pos = objran.Next(1, charArr.Length);
        if (!strrandom.Contains(charArr.GetValue(pos).ToString())) strrandom += charArr.GetValue(pos);
        else i--;
    return strrandom;
// End OTP Generation function
// Start Send OTP code on button click
protected void btnSendOTP_Click(object sender, EventArgs e) {
    string otp = Generate_otp();
    string mobileNo = txtmobileno.Text.Trim();
    string SMSContents = "", smsResult = "";
    SMSContents = otp + " is your One-Time Password, valid for 10 minutes only, Please do not share your OTP with anyone.";
    smsResult = SendSMS(mobileNo, SMSContents);
    lblMsg.Text = " OTP is sent to your registered mobile no.";
    lblMsg.CssClass = "green";
    mobileNo = string.Empty;
    Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "countdown()", true);
// End Send OTP code on button click
// SMS Sending function
public static string SendSMS(string MblNo, string Msg) {
    string MainUrl = "SMSAPIURL"; //Here need to give SMS API URL
    string UserName = "username"; //Here need to give username
    string Password = "Password"; //Here need to give Password
    string SenderId = "SenderId";
    string strMobileno = MblNo;
    string URL = "";
    URL = MainUrl + "username=" + UserName + "&msg_token=" + Password + "&sender_id=" + SenderId + "&message=" + HttpUtility.UrlEncode(Msg).Trim() + "&mobile=" + strMobileno.Trim() + "";
    string strResponce = GetResponse(URL);
    string msg = "";
    if (strResponce.Equals("Fail")) {
        msg = "Fail";
    } else {
        msg = strResponce;
    return msg;
// End SMS Sending function
// Get Response function
public static string GetResponse(string smsURL) {
    try {
        WebClient objWebClient = new WebClient();
        System.IO.StreamReader reader = new System.IO.StreamReader(objWebClient.OpenRead(smsURL));
        string ResultHTML = reader.ReadToEnd();
        return ResultHTML;
    } catch (Exception) {
        return "Fail";
// End Get Response function

What is GEEK

Buddha Community

How To Send OTP SMS On User Mobile Using ASP.NET C# in 5 simple steps.
Einar  Hintz

Einar Hintz


jQuery Ajax CRUD in ASP.NET Core MVC with Modal Popup

In this article, we’ll discuss how to use jQuery Ajax for ASP.NET Core MVC CRUD Operations using Bootstrap Modal. With jQuery Ajax, we can make HTTP request to controller action methods without reloading the entire page, like a single page application.

To demonstrate CRUD operations – insert, update, delete and retrieve, the project will be dealing with details of a normal bank transaction. GitHub repository for this demo project : https://bit.ly/33KTJAu.

Sub-topics discussed :

  • Form design for insert and update operation.
  • Display forms in modal popup dialog.
  • Form post using jQuery Ajax.
  • Implement MVC CRUD operations with jQuery Ajax.
  • Loading spinner in .NET Core MVC.
  • Prevent direct access to MVC action method.

Create ASP.NET Core MVC Project

In Visual Studio 2019, Go to File > New > Project (Ctrl + Shift + N).

From new project window, Select Asp.Net Core Web Application_._

Image showing how to create ASP.NET Core Web API project in Visual Studio.

Once you provide the project name and location. Select Web Application(Model-View-Controller) and uncheck HTTPS Configuration. Above steps will create a brand new ASP.NET Core MVC project.

Showing project template selection for .NET Core MVC.

Setup a Database

Let’s create a database for this application using Entity Framework Core. For that we’ve to install corresponding NuGet Packages. Right click on project from solution explorer, select Manage NuGet Packages_,_ From browse tab, install following 3 packages.

Showing list of NuGet Packages for Entity Framework Core

Now let’s define DB model class file – /Models/TransactionModel.cs.

public class TransactionModel
    public int TransactionId { get; set; }

    [Column(TypeName ="nvarchar(12)")]
    [DisplayName("Account Number")]
    [Required(ErrorMessage ="This Field is required.")]
    [MaxLength(12,ErrorMessage ="Maximum 12 characters only")]
    public string AccountNumber { get; set; }

    [Column(TypeName ="nvarchar(100)")]
    [DisplayName("Beneficiary Name")]
    [Required(ErrorMessage = "This Field is required.")]
    public string BeneficiaryName { get; set; }

    [Column(TypeName ="nvarchar(100)")]
    [DisplayName("Bank Name")]
    [Required(ErrorMessage = "This Field is required.")]
    public string BankName { get; set; }

    [Column(TypeName ="nvarchar(11)")]
    [DisplayName("SWIFT Code")]
    [Required(ErrorMessage = "This Field is required.")]
    public string SWIFTCode { get; set; }

    [Required(ErrorMessage = "This Field is required.")]
    public int Amount { get; set; }

    [DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}")]
    public DateTime Date { get; set; }


Here we’ve defined model properties for the transaction with proper validation. Now let’s define  DbContextclass for EF Core.

#asp.net core article #asp.net core #add loading spinner in asp.net core #asp.net core crud without reloading #asp.net core jquery ajax form #asp.net core modal dialog #asp.net core mvc crud using jquery ajax #asp.net core mvc with jquery and ajax #asp.net core popup window #bootstrap modal popup in asp.net core mvc. bootstrap modal popup in asp.net core #delete and viewall in asp.net core #jquery ajax - insert #jquery ajax form post #modal popup dialog in asp.net core #no direct access action method #update #validation in modal popup

Hire ASP.Net Developers

Looking to outsource your asp dot net development requirement?

ASP.Net is a special feature of the DOT Net framework created by Microsoft. At HourlyDeveloper.io, we have a team of experienced ASP.Net developers who are experts in delivering custom solutions based on your business requirements. Hire ASP.Net Developers who will provide tailored solutions to facilitate your business growth.

Consult with experts: https://bit.ly/3fNpVqr

#hire asp.net developers #asp.net development company #asp.net development services #asp.net development #asp.net developer #asp.net

Einar  Hintz

Einar Hintz


MVC User Registration & Login with ASP.NET Core Identity

User registration and authentication are mandatory in any application when you have little concern about privacy. Hence all most all application development starts with an authentication module. In this article, we will discuss the quickest way to use **ASP.NET Core Identity for User Login and Registration **in a new or existing MVC application.

Sub-topics discussed :

  • How to add ASP.NET Core Identity to MVC application.
  • Customize ASP.NET Core Identity.
  • Identity.UI Design Customization.
  • Next step.


ASP.NET Core Identity is an API, which provides both user interface(UI) and functions for user authentication, registration, authorization, etc. Modules/ APIs like this will really be helpful and fasten the development process. It comes with ASP.NET Core Framework and used in many applications before. Which makes the API more dependable and trustworthy.

ASP.NET Core MVC with user authentication can easily be accomplished using Identity.UI. While creating the MVC project, you just need to select Authentication as Individual User Accounts.

Showing how to create an MVC application with ASP.NET Core Identity API

The rest will be handled by ASP.NET Core Identity UI. It already contains razor view pages and backend codes for an authentication system. But that’s not what we want in most of the cases. we want to customize ASP.NET Core Identity as per our requirement. That’s what we do here.

Create an ASP.NET Core MVC Project

First of all, I will create a brand new ASP.NET Core MVC application without any authentication selected. We could add ASP.NET Core Identity later into the project.

In Visual Studio 2019, Go to File > New > Project (Ctrl + Shift + N). From new project window, select ASP.NET Core Web Application.

Create an ASP.NET Core Web application

Once you provide the project name and location. A new window will be opened as follows, Select _Web Application(Model-View-Controller), _uncheck _HTTPS Configuration _and DO NOT select any authentication method. Above steps will create a brand new ASP.NET Core MVC project.

Select Model View Controller templet under .NET Core

#asp.net core article #asp.net core #add asp.net core identity to existing project #asp.net core identity in mvc #asp.net core mvc login and registration #login and logout in asp.net core

Aketch  Rachel

Aketch Rachel


How to send SMS with Twilio in ASP.NET Core 5 and C#

How to Send an SMS with ASP.NET Core

Let’s get started with setting up a Twilio SMS account. When we create a Twilio account, we are going to be given a free trial account with a 15.50 USD. We can use the trial balance toward purchasing a phone number and sending and receiving messages.

#c# #dotnet core #how to #send sms with twilio #twilio send sms #using twilio to send sms

Sending Email in Asp Net Core MVC 5 using Quick Mailer


#sending email in asp net core mvc 5 using quick mailer #sending email in asp net core #sending email in c#