一、基本配置


  1. 全局配置 Global.asax

public class WebApiApplication : System.Web.HttpApplication
{
  protected void Application_Start()
  {
    GlobalConfiguration.Configure(WebApiConfig.Register);
    GlobalConfiguration.Configuration.Filters.Add(new WebApiActionDebugFilter());     //配置返回的时间类型数据格式
    GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.Converters.Add(
      new Newtonsoft.Json.Converters.IsoDateTimeConverter()
    {
      DateTimeFormat = "yyyy-MM-dd HH:mm:ss"
    }
    );
    GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();   }
}

  2. 日志记录 WebApiActionDebugFilter

 public class WebApiActionDebugFilter : System.Web.Http.Filters.ActionFilterAttribute
{ /// <summary>
/// 是否开启调试
/// </summary>
private bool _isDebugLog = (ConfigurationManager.AppSettings["isDebugLog"]) != null && ConfigurationManager.AppSettings["isDebugLog"].ToString().ToLower() == "false" ? false : true;
private readonly ILog txtlog = log4net.LogManager.GetLogger("txtLogger"); public override void OnActionExecuting(System.Web.Http.Controllers.HttpActionContext context)
{
//log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo(AppDomain.CurrentDomain.BaseDirectory + @"xmlconfig/log4net.config"));
base.OnActionExecuting(context); if (_isDebugLog)
{
try
{
var controllerName = context.ControllerContext.ControllerDescriptor.ControllerName;
var controller = context.ControllerContext.Controller.GetType();
var actionName = context.ActionDescriptor.ActionName;
var descr = string.Empty;
var members = controller.GetMethods(); foreach (var member in members)
{
if (member.Name == actionName)//如果是obejct
{
object[] attrs = member.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), true);
if (attrs.Length > )
descr = (attrs[] as System.ComponentModel.DescriptionAttribute).Description;
break;
}
} var txtParams = ""; //******读流会影响图片上传的接口获取不到流了******
//var task = context.Request.Content.ReadAsStreamAsync();
//using (System.IO.Stream sm = task.Result)
//{
// if (sm != null && sm.Length > 0)
// {
// sm.Seek(0, SeekOrigin.Begin);
// int len = (int)sm.Length;
// byte[] inputByts = new byte[len];
// sm.Read(inputByts, 0, len);
// //sm.Close();
// txtParams = Encoding.UTF8.GetString(inputByts);
// }
//} if (context.Request.Method.ToString().ToLower() == "get")
{
txtParams = context.Request.RequestUri.Query;
}
else if (context.Request.Method.ToString().ToLower() == "post")
{
if (context.ActionArguments != null && context.ActionArguments.Count > )
{
txtParams = JsonConvert.SerializeObject(context.ActionArguments);
}
} var beginRequestTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
context.Request.Content.Headers.Add("BeginRequestTime", beginRequestTime);
//写文件
var logInfo = new
{
CallTime = beginRequestTime,
ActionType = "请求",
ControllerName = controllerName,
ActionName = actionName,
Description = descr,
Params = txtParams,
ReqGuid = context.Request.GetCorrelationId().ToString().Replace("-", "")
}; Console.WriteLine(logInfo); Util.ExecuteInvoke(() => txtlog.Info(GetObjetJson(logInfo)));
}
catch (Exception ex)
{
var response = new HttpResponseMessage(HttpStatusCode.BadRequest)
{
Content = new StringContent("请求出错,详细信息如下:"+Environment.NewLine+ex.Message),
ReasonPhrase = "请求不被允许"
};
throw new HttpResponseException(response);
//txtlog.Info("请求出错"+ ex.Message + ex.StackTrace);
}
}
}
public override void OnActionExecuted(System.Web.Http.Filters.HttpActionExecutedContext context)
{
base.OnActionExecuted(context); if (_isDebugLog)
{
try
{
var controllerName = context.ActionContext.ControllerContext.ControllerDescriptor.ControllerName;
var actionName = context.ActionContext.ActionDescriptor.ActionName;
var txtResult = context.Response.Content.ReadAsStringAsync().Result;
var endTime = DateTime.Now;
var reqGuid = context.ActionContext.Request.GetCorrelationId().ToString().Replace("-", "");
var beginTime = context.Request.Content.Headers.GetValues("BeginRequestTime").FirstOrDefault();
var execTime = Util.ExecTimeDiff(Convert.ToDateTime(beginTime), endTime); //写文件
var logInfo = new
{
CallTime = endTime.ToString("yyyy-MM-dd HH:mm:ss.fff"),
ExecTime = execTime,
ActionType = "响应",
ControllerName = controllerName,
ActionName = actionName,
Params = txtResult,
ReqGuid = reqGuid
}; Util.ExecuteInvoke(() => txtlog.Info(GetObjetJson(logInfo)));
}
catch (Exception ex)
{
txtlog.Info("响应出错" + ex.Message + ex.StackTrace);
}
}
} private string GetObjetJson(object message)
{
var retStr = "";
try
{
if (message != null)
{
var json = JsonConvert.SerializeObject(message);
retStr = json;
//if (json != null) retStr = json.Replace("\\\"", "");
}
}
catch (Exception)
{
// ignored
}
return retStr;
}
}

  3. 文件上传

 public class SysUpdateController : ApiController
{
[HttpGet]
[ActionName("getfilemd5")]
public HttpResponseMessage GetFileMD5(string fileName, string parentDir)
{
HttpResponseMessage response = new HttpResponseMessage();
try
{
string baseDirectory = Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath("~/"), string.Format("{0}\\", parentDir));
fileName = Path.Combine(baseDirectory, fileName);
string content = "";
if (!File.Exists(fileName))
{
content = "未知错误";
}
else
{
content = GetMD5HashFromFile(fileName);
}
response.Content = new StringContent(content, System.Text.Encoding.UTF8, "text/json");
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
}
catch (Exception ex)
{
response.Content = new StringContent("未知错误:" + ex.Message, System.Text.Encoding.UTF8, "text/json");
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
}
return response;
}
[HttpGet]
[ActionName("getpackage")]
public HttpResponseMessage GetPackage()
{
HttpResponseMessage response = new HttpResponseMessage();
try
{
string baseDirectory = System.Web.Hosting.HostingEnvironment.MapPath("~/");
string filePath = Path.Combine(baseDirectory, "QCPackage\\");
string[] files = Directory.GetFiles(filePath); if (files.Length > )
{
filePath = files[];
FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
response.Content = new StreamContent(fileStream);
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
response.Content.Headers.ContentDisposition.FileName = Path.GetFileName(filePath);
// 这句话要告诉浏览器要下载文件
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
response.Content.Headers.ContentLength = new FileInfo(filePath).Length;
}
else
{
response.Content = new StringContent("未知错误", System.Text.Encoding.UTF8, "text/json");
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
}
}
catch
{
response.Content = new StringContent("未知错误", System.Text.Encoding.UTF8, "text/json");
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
}
return response;
} /// <summary>
/// 文件下载
/// </summary>
/// <param name="filePath "></param>
/// <returns></returns>
[HttpGet]
[ActionName("getfiles")]
public HttpResponseMessage GetFiles(string parentDir)
{
HttpResponseMessage response = new HttpResponseMessage();
try
{
List<string> files = new List<string>();
string baseDirectory = Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath("~/"), string.Format("{0}\\", parentDir));
string[] rootPathFiles = Directory.GetFiles(baseDirectory);
files.AddRange(rootPathFiles);
string[] rootPathDirectories = Directory.GetDirectories(baseDirectory);
foreach (string directory in rootPathDirectories)
{
GetFiles(directory, files);
}
for (int i = ; i < files.Count; i++)
{
files[i] = System.Text.Encoding.UTF8.GetString(System.Text.Encoding.UTF8.GetBytes(files[i].Replace(baseDirectory, "")));
} string content = Newtonsoft.Json.JsonConvert.SerializeObject(files);
response.Content = new StringContent(content, System.Text.Encoding.UTF8, "text/json");
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
}
catch
{
response.Content = new StringContent("未知错误", System.Text.Encoding.UTF8, "text/json");
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
}
return response;
} /// <summary>
/// 文件下载
/// </summary>
/// <param name="filePath "></param>
/// <returns></returns>
[HttpGet]
[ActionName("upgrade")]
public HttpResponseMessage Upgrade(string fileName, string parentDir)
{
string baseDirectory = Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath("~/"), string.Format("{0}\\", parentDir));
string filePath = Path.Combine(baseDirectory, fileName); FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
HttpResponseMessage response = new HttpResponseMessage();
response.Content = new StreamContent(fileStream);
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
response.Content.Headers.ContentDisposition.FileName = Path.GetFileName(filePath);
// 这句话要告诉浏览器要下载文件
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
response.Content.Headers.ContentLength = new FileInfo(filePath).Length;
return response;
} private void GetFiles(string filePath, List<string> files)
{
string[] currentPathFiles = Directory.GetFiles(filePath);
string[] currentPathDirectories = Directory.GetDirectories(filePath);
files.AddRange(currentPathFiles);
foreach (string currentPath in currentPathDirectories)
{
GetFiles(currentPath, files);
}
} private string GetMD5HashFromFile(string fileName)
{
try
{
FileStream file = new FileStream(fileName, FileMode.Open);
System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] retVal = md5.ComputeHash(file);
file.Close(); StringBuilder sb = new StringBuilder();
for (int i = ; i < retVal.Length; i++)
{
sb.Append(retVal[i].ToString("x2"));
}
return sb.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
}

  4. FTPHelper

public class FTPHelper
{
/// <summary>
/// FTP请求对象
/// </summary>
FtpWebRequest request = null;
/// <summary>
/// FTP响应对象
/// </summary>
FtpWebResponse response = null;
/// <summary>
/// FTP服务器地址
/// </summary>
public string ftpURI { get; private set; }
/// <summary>
/// FTP服务器IP
/// </summary>
public string ftpServerIP { get; private set; }
/// <summary>
/// FTP服务器默认目录
/// </summary>
public string ftpRemotePath { get; private set; }
/// <summary>
/// FTP服务器登录用户名
/// </summary>
public string ftpUserID { get; private set; }
/// <summary>
/// FTP服务器登录密码
/// </summary>
public string ftpPassword { get; private set; } /// <summary>
/// 初始化
/// </summary>
/// <param name="FtpServerIP">FTP连接地址</param>
/// <param name="FtpRemotePath">指定FTP连接成功后的当前目录, 如果不指定即默认为根目录</param>
/// <param name="FtpUserID">用户名</param>
/// <param name="FtpPassword">密码</param>
public FTPHelper(string ftpServerIP, string ftpRemotePath, string ftpUserID, string ftpPassword)
{
this.ftpServerIP = ftpServerIP;
this.ftpRemotePath = ftpRemotePath;
this.ftpUserID = ftpUserID;
this.ftpPassword = ftpPassword;
this.ftpURI = "ftp://" + ftpServerIP + "/" + ftpRemotePath + "/";
}
~FTPHelper()
{
if (response != null)
{
response.Close();
response = null;
}
if (request != null)
{
request.Abort();
request = null;
}
}
/// <summary>
/// 建立FTP链接,返回响应对象
/// </summary>
/// <param name="uri">FTP地址</param>
/// <param name="ftpMethod">操作命令</param>
/// <returns></returns>
private FtpWebResponse Open(Uri uri, string ftpMethod)
{
request = (FtpWebRequest)FtpWebRequest.Create(uri);
request.Method = ftpMethod;
request.UseBinary = true;
request.KeepAlive = false;
//request.UsePassive = false;//主动模式
request.Credentials = new NetworkCredential(this.ftpUserID, this.ftpPassword);
return (FtpWebResponse)request.GetResponse();
} /// <summary>
/// 建立FTP链接,返回请求对象
/// </summary>
/// <param name="uri">FTP地址</param>
/// <param name="ftpMethod">操作命令</param>
private FtpWebRequest OpenRequest(Uri uri, string ftpMethod)
{
request = (FtpWebRequest)WebRequest.Create(uri);
request.Method = ftpMethod;
request.UseBinary = true;
request.KeepAlive = false;
request.Credentials = new NetworkCredential(this.ftpUserID, this.ftpPassword);
return request;
}
/// <summary>
/// 创建目录
/// </summary>
/// <param name="remoteDirectoryName">目录名</param>
public void CreateDirectory(string remoteDirectoryName)
{
response = Open(new Uri(ftpURI + remoteDirectoryName), WebRequestMethods.Ftp.MakeDirectory);
}
/// <summary>
/// 更改目录或文件名
/// </summary>
/// <param name="currentName">当前名称</param>
/// <param name="newName">修改后新名称</param>
public void ReName(string currentName, string newName)
{
request = OpenRequest(new Uri(ftpURI + currentName), WebRequestMethods.Ftp.Rename);
request.RenameTo = newName;
response = (FtpWebResponse)request.GetResponse();
}
/// <summary>
/// 切换当前目录
/// </summary>
/// <param name="IsRoot">true:绝对路径 false:相对路径</param>
public void GotoDirectory(string DirectoryName, bool IsRoot)
{
if (IsRoot)
ftpRemotePath = DirectoryName;
else
ftpRemotePath += "/" + DirectoryName; ftpURI = "ftp://" + ftpServerIP + "/" + ftpRemotePath + "/";
}
/// <summary>
/// 删除目录(包括下面所有子目录和子文件)
/// </summary>
/// <param name="remoteDirectoryName">要删除的带路径目录名:如web/test</param>
/*
* 例:删除test目录
FTPHelper helper = new FTPHelper("x.x.x.x", "web", "user", "password");
helper.RemoveDirectory("web/test");
*/
public void RemoveDirectory(string remoteDirectoryName)
{
GotoDirectory(remoteDirectoryName, true);
var listAll = ListFilesAndDirectories();
foreach (var m in listAll)
{
if (m.IsDirectory)
RemoveDirectory(m.Path);
else
DeleteFile(m.Name);
}
GotoDirectory(remoteDirectoryName, true);
response = Open(new Uri(ftpURI), WebRequestMethods.Ftp.RemoveDirectory);
}
/// <summary>
/// 文件上传
/// </summary>
/// <param name="localFilePath">本地文件路径</param>
public void Upload(string localFilePath)
{
FileInfo fileInf = new FileInfo(localFilePath);
request = OpenRequest(new Uri(ftpURI + fileInf.Name), WebRequestMethods.Ftp.UploadFile);
request.ContentLength = fileInf.Length;
int buffLength = ;
byte[] buff = new byte[buffLength];
int contentLen;
using (var fs = fileInf.OpenRead())
{
using (var strm = request.GetRequestStream())
{
contentLen = fs.Read(buff, , buffLength);
while (contentLen != )
{
strm.Write(buff, , contentLen);
contentLen = fs.Read(buff, , buffLength);
}
}
}
} public string Upload(byte[] buff)
{
string fileName = DateTime.Now.ToFileTime().ToString() + ".png";
string path = DateTime.Now.ToString("yyyyMM").ToString();
if (!IsExist(path))
CreateDirectory(path); path += "/" + fileName; request = OpenRequest(new Uri(ftpURI + path), WebRequestMethods.Ftp.UploadFile);
using (var strm = request.GetRequestStream())
{
strm.Write(buff, , buff.Length);
} return path;
} /// <summary>
/// 上传best64图片
/// </summary>
/// <param name="base64String"></param>
/// <returns></returns>
public string UploadBase64(string base64String)
{
string fileName = DateTime.Now.ToFileTime().ToString() + ".png";
string path = DateTime.Now.ToString("yyyyMM").ToString();
if (!IsExist(path))
CreateDirectory(path); path += "/" + fileName; request = OpenRequest(new Uri(ftpURI + path), WebRequestMethods.Ftp.UploadFile);
request.ContentLength = base64String.Length; byte[] byteArray = Convert.FromBase64String(base64String);
using (var strm = request.GetRequestStream())
{
strm.Write(byteArray, , byteArray.Length);
} return path;
} /// <summary>
/// 下载
/// </summary>
/// <param name="saveFilePath">下载后的保存路径</param>
/// <param name="downloadFileName">要下载的文件名</param>
public void Download(string saveFilePath, string downloadFileName)
{
using (FileStream outputStream = new FileStream(saveFilePath + "\\" + downloadFileName, FileMode.Create))
{
response = Open(new Uri(ftpURI + downloadFileName), WebRequestMethods.Ftp.DownloadFile);
using (Stream ftpStream = response.GetResponseStream())
{
long cl = response.ContentLength;
int bufferSize = ;
int readCount;
byte[] buffer = new byte[bufferSize];
readCount = ftpStream.Read(buffer, , bufferSize);
while (readCount > )
{
outputStream.Write(buffer, , readCount);
readCount = ftpStream.Read(buffer, , bufferSize);
}
}
}
} /// <summary>
/// 获取文件best64编码
/// </summary>
/// <param name="downloadFileName"></param>
/// <returns></returns>
public string DownloadBest64(string downloadFileName)
{
response = Open(new Uri(ftpURI + downloadFileName), WebRequestMethods.Ftp.DownloadFile);
var ftpStream = response.GetResponseStream();
var ms = new MemoryStream(); var bufferSize = ;
var buffer = new byte[bufferSize];
while ((bufferSize = ftpStream.Read(buffer, , bufferSize)) > )
{
ms.Write(buffer, , bufferSize);
}
var bast64 = Convert.ToBase64String(ms.ToArray()); return bast64;
} /// <summary>
/// 删除文件
/// </summary>
/// <param name="remoteFileName">要删除的文件名</param>
public void DeleteFile(string remoteFileName)
{
response = Open(new Uri(ftpURI + remoteFileName), WebRequestMethods.Ftp.DeleteFile);
} /// <summary>
/// 获取当前目录的文件和一级子目录信息
/// </summary>
/// <returns></returns>
public List<FileStruct> ListFilesAndDirectories()
{
var fileList = new List<FileStruct>();
response = Open(new Uri(ftpURI), WebRequestMethods.Ftp.ListDirectoryDetails);
using (var stream = response.GetResponseStream())
{
using (var sr = new StreamReader(stream))
{
string line = null;
while ((line = sr.ReadLine()) != null)
{
//line的格式如下:
//08-18-13 11:05PM <DIR> aspnet_client
//09-22-13 11:39PM 2946 Default.aspx
DateTime dtDate = DateTime.ParseExact(line.Substring(, ), "MM-dd-yy", null);
DateTime dtDateTime = DateTime.Parse(dtDate.ToString("yyyy-MM-dd") + line.Substring(, ));
string[] arrs = line.Split(' ');
var model = new FileStruct()
{
IsDirectory = line.IndexOf("<DIR>") > ? true : false,
CreateTime = dtDateTime,
Name = arrs[arrs.Length - ],
Path = ftpRemotePath + "/" + arrs[arrs.Length - ]
};
fileList.Add(model);
}
}
}
return fileList;
}
/// <summary>
/// 列出当前目录的所有文件
/// </summary>
public List<FileStruct> ListFiles()
{
var listAll = ListFilesAndDirectories();
var listFile = listAll.Where(m => m.IsDirectory == false).ToList();
return listFile;
}
/// <summary>
/// 列出当前目录的所有一级子目录
/// </summary>
public List<FileStruct> ListDirectories()
{
var listAll = ListFilesAndDirectories();
var listFile = listAll.Where(m => m.IsDirectory == true).ToList();
return listFile;
}
/// <summary>
/// 判断当前目录下指定的子目录或文件是否存在
/// </summary>
/// <param name="remoteName">指定的目录或文件名</param>
public bool IsExist(string remoteName)
{
var list = ListFilesAndDirectories();
if (list.Count(m => m.Name == remoteName) > )
return true;
return false;
}
/// <summary>
/// 判断当前目录下指定的一级子目录是否存在
/// </summary>
/// <param name="RemoteDirectoryName">指定的目录名</param>
public bool IsDirectoryExist(string remoteDirectoryName)
{
var listDir = ListDirectories();
if (listDir.Count(m => m.Name == remoteDirectoryName) > )
return true;
return false;
}
/// <summary>
/// 判断当前目录下指定的子文件是否存在
/// </summary>
/// <param name="RemoteFileName">远程文件名</param>
public bool IsFileExist(string remoteFileName)
{
var listFile = ListFiles();
if (listFile.Count(m => m.Name == remoteFileName) > )
return true;
return false;
}
}

从文件流读取

var paths = string.Empty;
var streamProvider = new MultipartMemoryStreamProvider();
//var dic = new Dictionary<string, string>();
await Request.Content.ReadAsMultipartAsync(streamProvider).ContinueWith(multipartContent =>
{
if (multipartContent.IsFaulted || multipartContent.IsCanceled) return; foreach (var content in multipartContent.Result.Contents)
{
if (content.Headers.ContentType == null || content.Headers.ContentType.MediaType == null ||
!content.Headers.ContentType.MediaType.Contains("image"))
//if (string.IsNullOrEmpty(content.Headers.ContentDisposition.FileName))
{
//var val = content.ReadAsStringAsync().Result;
//dic.Add(content.Headers.ContentDisposition.Name.Replace("\"", ""), val);
}
else
{
var bytes = content.ReadAsByteArrayAsync().Result;
var path = ftp.Upload(bytes);
paths += path + ",";
}
}
});

WebAPI 笔记的更多相关文章

  1. WebApi笔记

    WebApi有一段时间没用了,这几天用webapi做了一个接口供第三方调用,又重新折腾了下,做个笔记记录下心得,防止遗忘. 1.webapi使用的RESTful风格的传参方式,其实就是充分利用HTTP ...

  2. Visual Studio 2015 Owin+MVC+WebAPI+ODataV4+EntityFrawork+Identity+Oauth2.0+AngularJS 1.x 学习笔记

    2016年,.net 会有很多大更新 ASP.NET 5 在此之前我都是用着古老的.net做开发的 (WebForm + IIS) 为了接下来应对 .net 的新功能,我特地去学习了一下基本的 MVC ...

  3. Asp.Net Core WebApi学习笔记(四)-- Middleware

    Asp.Net Core WebApi学习笔记(四)-- Middleware 本文记录了Asp.Net管道模型和Asp.Net Core的Middleware模型的对比,并在上一篇的基础上增加Mid ...

  4. 笔记-ASP.NET WebApi

    本文是针对ASP.NET WepApi 2 的笔记. Web API 可返回的结果: 1.void 2.HttpResponseMessage 3.IHttpActionResult 4.其他类型 返 ...

  5. WebAPI调用笔记 ASP.NET CORE 学习之自定义异常处理 MySQL数据库查询优化建议 .NET操作XML文件之泛型集合的序列化与反序列化 Asp.Net Core 轻松学-多线程之Task快速上手 Asp.Net Core 轻松学-多线程之Task(补充)

    WebAPI调用笔记   前言 即时通信项目中初次调用OA接口遇到了一些问题,因为本人从业后几乎一直做CS端项目,一个简单的WebAPI调用居然浪费了不少时间,特此记录. 接口描述 首先说明一下,基于 ...

  6. 路由其实也可以很简单-------Asp.net WebAPI学习笔记(一) ASP.NET WebApi技术从入门到实战演练 C#面向服务WebService从入门到精通 DataTable与List<T>相互转换

    路由其实也可以很简单-------Asp.net WebAPI学习笔记(一)   MVC也好,WebAPI也好,据我所知,有部分人是因为复杂的路由,而不想去学的.曾经见过一位程序猿,在他MVC程序中, ...

  7. ASP.Net MVC开发基础学习笔记:五、区域、模板页与WebAPI初步

    一.区域—麻雀虽小,五脏俱全的迷你MVC项目 1.1 Area的兴起 为了方便大规模网站中的管理大量文件,在ASP.NET MVC 2.0版本中引入了一个新概念—区域(Area). 在项目上右击创建新 ...

  8. 【笔记】Asp.Net WebApi对js POST带参数跨域请求的支持方案

    先说下需求:在原来的WebApi项目中增加对js跨域的请求支持,请求方式:以POST为主,webapi路由规则根据原项目需求修改如下: public static void Register(Http ...

  9. 【读书笔记】WebApi 和 SPA(单页应用)--knockout的使用

    Web API从MVC4开始出现,可以服务于Asp.Net下的任何web应用,本文将介绍Web api在单页应用中的使用.什么是单页应用?Single-Page Application最常用的定义:一 ...

随机推荐

  1. Flutter移动电商实战 --(45)详细页_说明区域UI编写

    pages/details_page/details_expain.dart 详情页面引用组件 效果展示: 最终代码: import 'package:flutter/material.dart'; ...

  2. java中 int、char、long各占多少字节数

    所谓的占用字节数 就是申请内存的时候所占的空间大小 byte    1字节 最小值是 -128(-2^7):    最大值是 127(2^7-1): boolean    至少1字节 这种类型只作为一 ...

  3. 导入GoogleClusterData到MySQL

    本篇随笔记录如何导入google-cluster-data-2011-1-2的 job_events和task_events到MySQL 1. 下载数据 download_job_events: im ...

  4. 【精华】PHP网站验证码不显示的终结解决方案

    PHP网站验证码不显示,这个是个很基础的PHP问题了,不过有点时候会比较让开发者比较头疼了.很多解决方案仅仅考虑到gd2,却忽略了另外一个很重要的因素了,相信在了解本教程之后,验证码不显示基本上就不算 ...

  5. 学习TypeScript 笔记

    TypeScript 什么是TypeScript TypeScript 是 JavaScript 的一个超集,支持 ECMAScript 6 标准. TypeScript 由微软开发的自由和开源的编程 ...

  6. 123457123457#1#-----com.threeapp.circlerunner01----儿童旋转跑酷游戏

    com.threeapp.circlerunner01----儿童旋转跑酷游戏

  7. spring redistemplate中setHashValueSerializer的设置

    笔者曾经对redis键值使用了不同类型的序列化方法 用过默认值.JdkSerializationRedisSerializer.StringRedisSerializer还用改以下自定类型的序列化工具 ...

  8. 查看某个进程PID对应的文件句柄数量,查看某个进程当前使用的文件句柄数量

    ================================ 1.linux所有句柄查询 lsof -n|awk '{print $2}'|sort|uniq -c |sort -nr|more ...

  9. 欧姆龙 EntherNet/IP(CIP报文格式)

    Enthip/IP_ CIP报文格式 测试Demo在文章末尾 注册请求帧: 0x65 0x00   注册请求命令 2byte 0x04,0x00   header长度2byte   < 封装头& ...

  10. golang web框架 beego 学习 (六) request body和module的映射

    router.go package routers import ( "gowebProject/controllers" "github.com/astaxie/bee ...