72 lines
2.3 KiB
Plaintext
72 lines
2.3 KiB
Plaintext
<%@ WebHandler Language="C#" Class="getShortCode" %>
|
|
|
|
using System;
|
|
using System.Web;
|
|
using System.Collections.Generic;
|
|
using System.Runtime.Serialization.Json;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using System.Web.Services.Protocols;
|
|
using System.Security.Cryptography;
|
|
using System.Text;
|
|
using System.Web.SessionState;
|
|
using System.Data;
|
|
|
|
public class getShortCode : IHttpHandler {
|
|
|
|
public void ProcessRequest (HttpContext context) {
|
|
result objRet = new result();
|
|
DataContractJsonSerializer json = new DataContractJsonSerializer(objRet.GetType());
|
|
context.Response.ContentType = "application/json;charset=utf-8";
|
|
context.Response.AddHeader("Access-Control-Allow-Origin", "*");
|
|
authPermission objAuth = new authPermission();
|
|
|
|
string project_uid = (context.Request["project_uid"] == null) ? "" : context.Request["project_uid"].ToString();
|
|
|
|
if (!objAuth.isLogin())
|
|
{
|
|
objRet.ret = "no";
|
|
objRet.err_code = "0001";
|
|
objRet.message = "尚未登入,請登入後使用";
|
|
json.WriteObject(context.Response.OutputStream, objRet);
|
|
return;
|
|
}
|
|
|
|
string shor_Code = globalClass.CreateCaseRandomCode(6);
|
|
Boolean isCheck = false;
|
|
|
|
while (isCheck == false) {
|
|
string checkString = string.Format("select * from url where url_code Collate SQL_Latin1_General_CP1_CS_AS = '{0}'", shor_Code);
|
|
autoBindDataTable checkSQL = new autoBindDataTable(checkString);
|
|
|
|
if (checkSQL.dataRows.Count == 0)
|
|
{
|
|
isCheck = true;
|
|
}
|
|
else {
|
|
shor_Code = globalClass.CreateCaseRandomCode(6);
|
|
}
|
|
}
|
|
|
|
objRet.ret = "yes";
|
|
objRet.shorCode = shor_Code;
|
|
|
|
json.WriteObject(context.Response.OutputStream, objRet);
|
|
return;
|
|
}
|
|
|
|
public class result {
|
|
public string ret = "no";
|
|
public string err_code = "0000";
|
|
public string message = "";
|
|
public string shorCode = "";
|
|
public string urlHeader = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + "/";
|
|
}
|
|
|
|
public bool IsReusable {
|
|
get {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
} |