Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vibhavsinha/c82239fea15888afd75b to your computer and use it in GitHub Desktop.
Save vibhavsinha/c82239fea15888afd75b to your computer and use it in GitHub Desktop.
Sample code to embed vdocipher videos with C# in ASP.NET MVC
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
using System.Web.Mvc;
namespace WebApplication1.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult About()
{
ViewBag.Message = "Your application description page.";
string video_id = "VIDEO_ID "; // This should be obtained from DB
// The API Secret should not be hard-coded inside the application
string api_secret = System.Web.Configuration.WebConfigurationManager.AppSettings["VdoCipher_API_Key"]; ;
string uri = "https://api.vdocipher.com/v2/otp/?video=" + video_id;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
using (StreamWriter writer = new StreamWriter(request.GetRequestStream(), Encoding.ASCII))
{
writer.Write("clientSecretKey=" + api_secret);
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
dynamic otp_data;
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
string json_otp = reader.ReadToEnd();
otp_data = JObject.Parse(json_otp);
}
ViewBag.otp = otp_data.otp;
return View();
}
public ActionResult Contact()
{
ViewBag.Message = "Your contact page.";
return View();
}
}
}
@{
ViewBag.Title = "About";
}
<h2>@ViewBag.Title.</h2>
<p>Use this area to provide additional information.</p>
<div id="@("vdo" + ViewBag.otp)" style="height:400px;width:640px;max-width:100%;"></div>
<script>
(function(v,i,d,e,o){v[o]=v[o]||{}; v[o].add = v[o].add || function V(a){ (v[o].d=v[o].d||[]).push(a);};
if(!v[o].l) { v[o].l=1*new Date(); a=i.createElement(d), m=i.getElementsByTagName(d)[0];
a.async=1; a.src=e; m.parentNode.insertBefore(a,m);}
})(window,document,'script','//de122v0opjemw.cloudfront.net/vdo.js','vdo');
vdo.add({
o: "@ViewBag.otp",
});
</script>
<configuration>
...........
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="VdoCipher_API_Key" value="VDOCIPHER_API_SECRET_KEY" />
</appSettings>
............
</configuration>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment