一、基本配置


  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. JMeter中计数器的使用

    添加计数器 计数器的引用,用于数据做区分 可以添加一个变量count,每次为了数据的唯一性,只要修改count就可以了,例如

  2. Docs-.NET-C#-指南-语言参考-预处理器指令:#undef(C# 参考)

    ylbtech-Docs-.NET-C#-指南-语言参考-预处理器指令:#undef(C# 参考) 1.返回顶部 1. #undef(C# 参考) 2018/06/30 #undef 允许你定义一个符 ...

  3. ctl +→ = MAC 触控板三指手势

    我只想发一个这个:一直用外接显示器,但是不舍得抛弃全屏程序的切换,即:触控板三指手势. 期间各种百度无果,最多找到出最多的是触发角: 今天终于发现了:ctl +→  =  MAC 触控板三指手势 (外 ...

  4. var和val的区别

    var是一个可变变量,这是一个可以通过重新分配来更改为另一个值的变量.这种声明变量的方式和java中声明变量的方式一样. val是一个只读变量,这种声明变量的方式相当于java中的final变量.一个 ...

  5. SecureCRT 8.1破解方式

    百度网盘下载,里面有破解程序和破解方式. 链接: https://pan.baidu.com/s/1wlhqnn-TE_mcOXOLljP-zg 密码: 3ffj

  6. Python编译出现错误SyntaxError: Non-ASCII character '\xe7' 时解决方法

    转载个解决办法:https://blog.csdn.net/wangchao701123/article/details/57084244 转自https://blog.csdn.net/jim742 ...

  7. 域名购买、SSL证书申请使用和本地服务映射外网

    万网购买域名 1.在如下网址购买,价格不是很贵,几块钱一年的都有:https://wanwang.aliyun.com/domain/?spm=5176.100251.111252.24.4ddd4f ...

  8. www.zhaoyueyi.cn

    2019/6/20这一天.我筹划了很久,准备搞点事情; 然后去阿里云上买下了我思虑已久的服务器以及域名,以前一直舍不得买,或许也是因为舍不得买的原因,我的技术一直很low,处于很肤浅的水平 虽然工作4 ...

  9. UIPath工具里面如何入力一览里面的数据

    问题描述: UIpath工具如何在网页里面入力一览多条的数据.例如:某个公司里面在自己的内部员工管理的软件里面手动入力公司员工的所有信息之后反馈到数据库当中. 解决方法: UIpath工具来入力数据, ...

  10. [转帖]Linux内核剖析(一)Linux的历史

    Linux内核剖析(一)Linux的历史 https://www.cnblogs.com/alantu2018/p/8991158.html Unix操作系统 Unix的由来 汤普逊和里奇最早是在贝尔 ...