Posts

Connecting SQL data from MVCapplication without EF

string connectionString = "Server=KCPC\\SQLEXPRESS;Database=Optician;User ID=sa;Password=123456;Trusted_Connection=False";             SqlConnection cnn = new SqlConnection(connectionString);             SqlCommand cmd = new SqlCommand();             cmd.Connection = cnn;             cmd.CommandType = System.Data.CommandType.StoredProcedure;             cmd.CommandText = "spPatientList";             cnn.Open();             SqlDataReader data = cmd.ExecuteReader();             while (data.Read())             {                 string sd = data["PatientCode"].ToString();             }             cnn.Close();

Develop recaptcha validation in c# backend and website

In Html  <div class="g-recaptcha" data-sitekey="@siteKey"></div>                                     <script src="https://www.google.com/recaptcha/api.js?hl=en" async defer></script> C# backend string EncodedResponse = Request.Form["g-Recaptcha-Response"]; bool IsCaptchaValid = (ReCaptchaClass.Validate(EncodedResponse, secretKey) == "True" ? true : false);  public class ReCaptchaClass     {         public static string Validate(string EncodedResponse, string secretKey)         {             var client = new WebClient();                   var GoogleReply = client.DownloadString(string.Format("https://www.google.com/recaptcha/api/siteverify?secret={0}&response={1}", secretKey, EncodedResponse));       ...

How can we find .net version in server or computer

Save following code as   xxxx.bat and double click to execute. @echo off SETLOCAL ENABLEDELAYEDEXPANSION if   "%1"=="/?" GOTO :DO_HELP if /I "%1"=="-h" GOTO :DO_HELP if /I "%1"=="-v" GOTO :DO_REG_INFO GOTO :DO_RELEASE_VER :DO_HELP echo Usage: %0 [ -v ^| -h ^| ^/? ] echo            Default: Returns the installed DotNet 4 version. echo -v         Verbose: Returns the all the DotNet 4 registry settings. echo -h or /?   This help screen. echo see: https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed echo. echo Release Number Ver.   Installations echo -------------- -----  ------------------------------------------------- echo 461310 0x709fe 4.7.1  All other Windows OS versions echo 461308 0x709fc 4.7.1  On Windows 10 Fall Creators Update echo 460805 0x70805 4.7    All other Windows OS versions ...

How to do google captcha in form submit in mvc controller

 string EncodedResponse = Request.Form["g-Recaptcha-Response"]; ReCaptchaClass.Validate(EncodedResponse, Request)  public class ReCaptchaClass     {         public static string Validate(string EncodedResponse, HttpRequestBase request)         {             var client = new WebClient();                         if (request.Url.Host == "www-mot-gov-sg.cwp.sg" || request.Url.Host == "www.mot.gov.sg")             {                 client.Proxy.Credentials = new NetworkCredential("www.mot.gov.sg", "NdjdrkhtvTze");             }             else if (request.Url.Host == "www-mot-gov-sg.cwp-stg.sg")             {                 clien...

How to get base domain url in asp.net mvc

How to get base domain url in asp.net mvc string webUrl = new Uri(Request.Url, Url.Content("~")).AbsoluteUri.TrimEnd('/');

How to send mail with attached file without store in local server

 How to send mail with attached file without store in local server string text = System.IO.File.ReadAllText(System.IO.Path.Combine(Server.MapPath("~/Mvc/Views/SinCairForm/EmailTemplate.cshtml")));                         emailBody = Razor.Parse(text, new { Message = "hello", Serial=DateTime.Now.Year.ToString(), WebURL= "http://localhost:49557" });                                               MailMessage mail = new MailMessage("dev@convertium.com", "kesikan@convertium.com", "Subject", emailBody);                         mail.IsBodyHtml = true;                         System.IO.MemoryStream stream = new System.IO.MemoryStream();               ...

How to render html string from razor view with model

This is sample example using RazorEngine; //this is for c# controller  string text = System.IO.File.ReadAllText(System.IO.Path.Combine(Server.MapPath("~/Mvc/Views/SinCairForm/EmailTemplate.cshtml")));                         emailBody = Razor.Parse(text, new { Message = "hello", Serial="2017-009", WebURL= "http://localhost:49557" }); //this is for view <div>@Model.Message</div> <div>@Model.Serial</div>