Skip to content

Instantly share code, notes, and snippets.

@vibhavsinha
Created March 7, 2016 12:48
Show Gist options
  • Save vibhavsinha/cd81f160c6d23093aa38 to your computer and use it in GitHub Desktop.
Save vibhavsinha/cd81f160c6d23093aa38 to your computer and use it in GitHub Desktop.
Sample implementation of vdocipher secure video embeddding in a ASP.NET web forms application Raw About.aspx
<%@ Page Title="About" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="About.aspx.cs" Inherits="WebApplication2.About" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<h2><%: Title %></h2>
<h3>Your application description page.</h3>
<p>Use this area to provide additional information.</p>
<div id="vdo<%=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: "<%=otp%>",
});
</script>
</asp:Content>
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.UI;
using System.Web.UI.WebControls;
namespace WebApplication2
{
public partial class About : Page
{
public string otp;
protected void Page_Load(object sender, EventArgs e)
{
otp = "";
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 = "API_SECRET_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);
otp = otp_data.otp;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment