WebAPI 笔记
一、基本配置
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 笔记的更多相关文章
- WebApi笔记
WebApi有一段时间没用了,这几天用webapi做了一个接口供第三方调用,又重新折腾了下,做个笔记记录下心得,防止遗忘. 1.webapi使用的RESTful风格的传参方式,其实就是充分利用HTTP ...
- Visual Studio 2015 Owin+MVC+WebAPI+ODataV4+EntityFrawork+Identity+Oauth2.0+AngularJS 1.x 学习笔记
2016年,.net 会有很多大更新 ASP.NET 5 在此之前我都是用着古老的.net做开发的 (WebForm + IIS) 为了接下来应对 .net 的新功能,我特地去学习了一下基本的 MVC ...
- Asp.Net Core WebApi学习笔记(四)-- Middleware
Asp.Net Core WebApi学习笔记(四)-- Middleware 本文记录了Asp.Net管道模型和Asp.Net Core的Middleware模型的对比,并在上一篇的基础上增加Mid ...
- 笔记-ASP.NET WebApi
本文是针对ASP.NET WepApi 2 的笔记. Web API 可返回的结果: 1.void 2.HttpResponseMessage 3.IHttpActionResult 4.其他类型 返 ...
- WebAPI调用笔记 ASP.NET CORE 学习之自定义异常处理 MySQL数据库查询优化建议 .NET操作XML文件之泛型集合的序列化与反序列化 Asp.Net Core 轻松学-多线程之Task快速上手 Asp.Net Core 轻松学-多线程之Task(补充)
WebAPI调用笔记 前言 即时通信项目中初次调用OA接口遇到了一些问题,因为本人从业后几乎一直做CS端项目,一个简单的WebAPI调用居然浪费了不少时间,特此记录. 接口描述 首先说明一下,基于 ...
- 路由其实也可以很简单-------Asp.net WebAPI学习笔记(一) ASP.NET WebApi技术从入门到实战演练 C#面向服务WebService从入门到精通 DataTable与List<T>相互转换
路由其实也可以很简单-------Asp.net WebAPI学习笔记(一) MVC也好,WebAPI也好,据我所知,有部分人是因为复杂的路由,而不想去学的.曾经见过一位程序猿,在他MVC程序中, ...
- ASP.Net MVC开发基础学习笔记:五、区域、模板页与WebAPI初步
一.区域—麻雀虽小,五脏俱全的迷你MVC项目 1.1 Area的兴起 为了方便大规模网站中的管理大量文件,在ASP.NET MVC 2.0版本中引入了一个新概念—区域(Area). 在项目上右击创建新 ...
- 【笔记】Asp.Net WebApi对js POST带参数跨域请求的支持方案
先说下需求:在原来的WebApi项目中增加对js跨域的请求支持,请求方式:以POST为主,webapi路由规则根据原项目需求修改如下: public static void Register(Http ...
- 【读书笔记】WebApi 和 SPA(单页应用)--knockout的使用
Web API从MVC4开始出现,可以服务于Asp.Net下的任何web应用,本文将介绍Web api在单页应用中的使用.什么是单页应用?Single-Page Application最常用的定义:一 ...
随机推荐
- SQL优化 | Oracle 绑定变量
之前整理过一篇有关绑定变量的文章,不太详细,重新补充一下. Oracle 绑定变量 http://www.cndba.cn/Dave/article/1275 一.绑定变量 bind variable ...
- word excel 未响应
前几天笔记本突然出现word 一打开就未响应的情况,导致完全无法使用.今天发现 excel 也出现了这种情况.今天终于下定决心解决这个问题. 百度上搜索了很多,找到了很多解决方案.总结如下. 一.禁用 ...
- opencv之调用摄像头
基础知识 # cap.set(propId, value) # 设置视频参数: propId - 设置的视频参数, value - 设置的参数值 # cap.isOpened() 返回 true/fa ...
- 009-多线程-JUC集合-Queue-LinkedBlockingDeque
一.概述 LinkedBlockingDeque是双向链表实现的双向并发阻塞队列.该阻塞队列同时支持FIFO和FILO两种操作方式,即可以从队列的头和尾同时操作(插入/删除):并且,该阻塞队列是支持线 ...
- flutter showDatePicker显示中文日期_Flutter时间控件显示中文
flutter showDatePicker showTimePicker显示中文日期 1.配置flutter_localizations依赖 找到pubspec.yaml配置flutter_loca ...
- 阶段5 3.微服务项目【学成在线】_day18 用户授权_07-动态查询用户权限-权限数据模型
3 动态查询用户权限 3.1 需求分析 截至目前在测试授权时使用的权限数据是静态数据,正常情况的流程是: 1.管理员给用户分配权限,权限数据写到数据库中. 2.认证服务在进行用户认证时从数据库读取用户 ...
- Apache三种工作模式详解
Apache HTTP服务器被设计为一个强大的.灵活的能够在多种平台以及不同环境下工作的服务器.这种模块化的设计就叫做“多进程处理模块”(Multi-Processing Module,MPM),也叫 ...
- Spring Aop(十五)——Aop原理之Advised接口
转发地址:https://www.iteye.com/blog/elim-2398726 Spring Aop原理之Advised接口 通过之前我们介绍的ProxyFactory我们知道,Spring ...
- SQLAlchemy相关文档
目录 参考文档 一.执行原生SQL语句 1.实例一 2.实例二 2.实例三 二.ORM操作 1.创建数据库表 (1)创建单表 (2)创建多个表并包含FK.M2M关系 2.操作数据库表 (1)基于sco ...
- tp5博客项目实战2
改虚拟主机 (用www.tp5.com直接访问替代localhost/blog/tp5/public) 1.host修改 位置C:\Windows\System32\drivers\etc 127.0 ...