1.下载 2.使用例子 Demo 概述:Quartz 是开源的定时任务工具类,默认每隔10秒执行一次任务,相当于C#的Timer,不断的循环执行(Start 方法),也可以随时停止(ShutDown方法)。 一 下载 下载地址:quartz 二 使用例子 Demo 1)引入程序集,必须引入三个,不然报错 2)IScheduler 和 IJob
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
public class Myjob : IJob { public const string DelayTime = "delay time"; public void Execute(IJobExecutionContext context) { string key = "quartzKeyCache"; if (System.Web.HttpRuntime.Cache[key] != null) { var temp = (int)System.Web.HttpRuntime.Cache[key]; System.Web.HttpRuntime.Cache[key] = temp + 1; } else { System.Web.HttpRuntime.Cache[key] = 1; } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
public class QuartzUlity { public static IScheduler sched; public static void Open() { ISchedulerFactory schedf = new StdSchedulerFactory(); sched = schedf.GetScheduler(); IJobDetail job = JobBuilder.Create<Myjob>().Build(); ITrigger trigger = (ITrigger)TriggerBuilder.Create().WithCronSchedule("/10 * * * * ?").Build(); sched.ScheduleJob(job, trigger); sched.Start(); } public static void Close() { sched.Shutdown(true); } } |
3)每隔10秒,修改一次缓存的值,可以打断点随时查看缓存里的实时值。 from:https://www.cnblogs.com/ligenyun/p/7729989.html
View Details错误的原因,npm版本问题; 解决办法: 1》更新到最新版本:npm install npm -g 要记住全局更新 2》回退版本:npm install -g npm@5.4.0 用cnpm 会快一些 from:https://www.cnblogs.com/hou-yuan-zhen/p/11703722.html
View DetailsGradle是一个基于Apache Ant和Apache Maven概念的项目自动化构建开源工具。它使用一种基于Groovy的特定领域语言(DSL)来声明项目设置,抛弃了基于XML的各种繁琐配置。面向Java应用为主。当前其支持的语言限于Java、Groovy、Kotlin和Scala。 到此不得不说另一个很火的工具maven,众所周知,maven的两大作用: ①:管理jar包 ②:构建项目 使用maven的缺点,XML配置文件的繁琐,特别是项目较大时,pom.xml配置眼花缭乱。 Gradle在maven的基础上,简化了配置文件,自动搜索Gradle等,使得我们创建管理项目更加简单。 一、下载,Gradle是压缩文件,下载解压即可。https://gradle.org/releases/ 这个是发布版,当然你还可以去 https://services.gradle.org/ 下载更新的版本。本人下载5.2.1的发布版 https://gradle.org/next-steps/?version=5.2.1&format=all 下载完毕后在本地目录解压即可。 二、配置环境变量:GRADLE_HOME 变量值为Gradle文件解压的实际路径,本文为例:E:\Gradle\gradle-5.2.1-all\gradle-5.2.1 在系统变量 path中加入:%GRADLE_HOME%\bin; 在cmd输入gradle -v验证是否安装成功 三、配置Gradle使用maven本地仓库,这样Gradle就不会重新下载已经存在maven本地仓库的jar包,从而节省时间和空间。 在环境变量中加入新的系统变量:GRADLE_USER_HOME 变量值是maven本地仓库的路径,本文为例C:\Users\Administrator\.m2\repository 此时,Gradle下载的文件将放到指定的仓库路径中。但是还需要修改build.gradle文件中加入mavenLocal() 引用本地仓库 repositories { //repositories闭包 mavenLocal() //配置先从本地仓库寻找jar包,优先寻找上一个配置,找到不执行下面的配置 mavenCentral() //配置从中央仓库寻找 google() //第三方仓库 jcenter() //代码托管库:设置之后可以在项目中轻松引用jcenter上的开源项目 } from:https://www.cnblogs.com/zeussbook/p/10556025.html
View DetailsServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true; 调用对方提供的webservice 方法之前,加上这一句,即可解决。 ———————————————— 版权声明:本文为CSDN博主「qq_42072922」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/qq_42072922/article/details/82620052
View Details在后台代码中进行基于https协议的请求时,我们经常会遇到一个错误:The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel(基础连接已经关闭: 未能为 SSL/TLS 安全通道建立信任关系。) 1,先加入命名空间: using System.Net.Security; using System.Security.Authentication; using System.Security.Cryptography.X509Certificates; 2,再重载CheckValidationResult方法,返回true private bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; } 3.然后在执行请求的代码之前加上 ServicePointManager.ServerCertificateValidationCallback = ValidateServerCertificate; 通过以上三步忽略证书的错误,但是不安全,其他解决方式可以参考https://stackoverflow.com/questions/703272/could-not-establish-trust-relationship-for-ssl-tls-secure-channel-soap 然而,对于一些https接口,加了上述代码之后,调用时回报错:基础连接已经关闭: 发送时发生错误 发生该错误的原因是,使用上述代码默认是以ssl安全协议进行的,但是有些https接口服务并没有使用ssl安全协议,具体参考 https://stackoverflow.com/questions/28286086/default-securityprotocol-in-net-4-5 解决方案1:硬编码,枚举出所有的安全协议,比较简单 在ServicePointManager.ServerCertificateValidationCallback = ValidateServerCertificate;这行代码前面加上如下代码: ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; 解决方案2:让OS自动选择安全协议(推荐) https://docs.microsoft.com/en-us/dotnet/framework/network-programming/tls from:https://blog.csdn.net/ujm097/article/details/89334667
View Details前面的文章说了怎么实现代理类的生成我使用。 在使用的过程 中我又碰到了一个很棘手的问题这是我的代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
//官方查询结果xml [WebMethod ] public OrderNciis GetNciisResult(string onName, string onId) { //获取授权文件 string inLicense = LotteryMethods.GetContext(11); //生成的WSDL类() nciicGetCondition objText = new nciicGetCondition(); //获取基础URL objText.Url = LotteryMethods.GetContext(12); //编码 objText.RequestEncoding = Encoding.UTF8; //创建证书文件 X509Certificate objx509 = new X509Certificate(System.Configuration.ConfigurationSettings.AppSettings["cd"].ToString().Trim()); //证书 objText.ClientCertificates.Add(objx509); //方式可有可无 objText.UserAgent = "Client Cert Sample"; //读XML文件 string inConditions = OrderNciisXml(onName, onId); //返回查询结果XML OrderNciis model = new OrderNciis(); model.onLottery = objText.nciicCheck(inLicense, inConditions); return model; } |
代码应该是没有问题,在本地的Vs里测试没有问题,如果在ISS里使用时报基础连接已经关闭: 未能为 SSL/TLS 安全通道建立信任关系”证书验证失败 城刚开始我还以为是文章路径的问题,结果不是, 接着找,后来认为是IIS里配置问题,还是不对,后来,看到 网上也有很多这的问题,但是没有真正解决的,一般都 是在说怎么生成代理类,还有带有证书的过程 我想了想,还是自己想办法解决吧,我把代理类分析了一下才知道 ,原来证书是在代理类里验证的,验证后会返回一个值 表示是否通过,这就好看了, 我们定义一个方法
1 2 3 4 5 6 7 |
private static bool RemoteCertificateValidate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors error){ // trust any certificate!!! System.Console.WriteLine("Warning, trust any certificate"); //为了通过证书验证,总是返回true return true; } |
只要这个方法返回为True不就完了吗?呵呵 还需要几个命名空间
1 2 3 4 |
using System.Net; using System.Net.Security; using System.Security.Authentication; using System.Security.Cryptography.X509Certificates; |
这个应该在什么时候调用呢,当然 是在构造器里合适些
1 2 3 4 5 6 |
/// <remarks/> public nciicGetCondition() { //验证服务器证书回调自动验证 ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateValidate; } |
from:https://www.cnblogs.com/sufei/archive/2010/03/23/1692811.html
View Details
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
public partial class _404 : System.Web.UI.Page { /// <summary> /// 目标服务器URL /// </summary> private readonly string targetUrl = "目标服务器"; protected void Page_Load(object sender, EventArgs e) { var folderPath = ""; try { // PrintSeverVariables(); // 取出资源地址 var fullUrl = Request.ServerVariables["QUERY_STRING"]; // 全地址 var resourceUrl = Regex.Replace(fullUrl, @"404;https?\://[^/]+", ""); // 取出文件名 var lastMatch = Regex.Match(resourceUrl, @"[^/]+(?!.*\.xlsx?)"); if (!lastMatch.Success || lastMatch.Groups.Count < 1) { Response.StatusCode = 404; return; } var fileName = lastMatch.Groups[0].Value.Split('?')[0]; if (string.IsNullOrEmpty(fileName) || fileName.IndexOf('.') < 0) { Response.StatusCode = 404; return; } // 扩展名 var extensionName = fileName.Split('.')[1].ToLower(); if (extensionName != "xls" && extensionName != "xlsx") // 只拉取excel文件 { Response.StatusCode = 404; return; } // 拉取文件 并保存 using (var stream = Get(targetUrl + resourceUrl)) { // 创建文件夹 folderPath = Server.MapPath(resourceUrl.Replace(fileName, "").Replace("/jq", "")); if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } // 保存文件 SaveFile(stream, folderPath + fileName); } // 转向拉取的静态资源 Response.ContentType = "application/octet-stream"; Response.WriteFile(folderPath + fileName); } catch (Exception ex) { Response.StatusCode = 404; return; } } /// <summary> /// 保存文件 /// </summary> /// <param name="stream"></param> /// <param name="fileName"></param> public void SaveFile(Stream stream, string fileName) { // 保存文件 using (var fs = new FileStream(fileName, FileMode.OpenOrCreate)) { stream.CopyTo(fs); fs.Close(); stream.Close(); } } /// <summary> /// Get请求 /// </summary> /// <param name="url"></param> /// <param name="postData"></param> /// <returns></returns> static Stream Get(string url) { //请求 var request = (HttpWebRequest)WebRequest.Create(url); request.Timeout = 600000; // 600秒 request.Method = "GET"; //接收 var response = (HttpWebResponse)request.GetResponse(); return response.GetResponseStream(); } /// <summary> /// 打印环境变量 /// </summary> void PrintSeverVariables() { foreach (string key in Request.ServerVariables) { Response.Write("<b>" + key + ":</b>" + Request.ServerVariables[key] + "<br>"); } } } |
View Details
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
public HttpResponseMessage ImportTemplate(string fileName) { var context = HttpContext.Current; var response = new HttpResponseMessage(HttpStatusCode.OK); var path = context.Server.MapPath("~/App_Data/" + fileName); if (string.IsNullOrEmpty(fileName) || !File.Exists(path)) { response = new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent($"<meta charset=\"utf-8\"><h3>【{fileName}】不存在。</h3>", Encoding.UTF8) }; response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html"); return response; } var stream = new FileStream(path, FileMode.Open, FileAccess.Read); response.Content = new StreamContent(stream); response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = HttpUtility.UrlEncode(fileName) }; response.Headers.Add("Access-Control-Expose-Headers", "FileName"); response.Headers.Add("FileName", HttpUtility.UrlEncode(fileName)); return response; } |
View Details
很久之前写的了,今天分享出来~
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
<% Dim re_url,mainUrl,fso mainUrl="http://localhost:81" On Error Resume Next Set fso=Server.CreateObject("Scripting.FileSystemObject") Set Retrieval = Server.CreateObject("MSXML2.ServerXMLHTTP") '获取404地址 If Instr(Request.ServerVariables("HTTP_HOST"),":") > 0 Then re_url = Replace(Lcase(Request.ServerVariables("QUERY_STRING")),"404;http://"&Request.ServerVariables("HTTP_HOST"),"") Else re_url = Replace(Lcase(Request.ServerVariables("QUERY_STRING")),"404;http://"&Request.ServerVariables("HTTP_HOST")&":"&Request.ServerVariables("SERVER_PORT"),"") End If '只抓取member中的文件 If InStr(re_url,"/member")=0 Then Server.Transfer("/404.html") If CheckURL(mainUrl&re_url) Then Call SaveGetFile(re_url,re_url) Else 'Response.Write(mainUrl&re_url) Server.Transfer("/404.html") Response.End End If Rem 检测资源是否存在 Function CheckURL(byval A_strUrl) Retrieval.Open "HEAD", A_strUrl, False Retrieval.Send() CheckURL = (Retrieval.Status = 200) End Function Rem 抓取并保存资源 Function SaveGetFile(RemoteFileUrl,SaveFilePaths) Dim Ads,GetRemoteData RemoteFileUrl=ReplaceTest("//+",RemoteFileUrl,"/") RemoteFileUrlU = Split(RemoteFileUrl, "/") If InStr(RemoteFileUrlU(UBound(RemoteFileUrlU)),".")=0 Then Server.Transfer("/404.html"):Response.End ' Dim arrFType ' arrFType=Split(RemoteFileUrlU(UBound(RemoteFileUrlU)),".") ' '只抓取静态页面和图片 ' Select Case LCase(arrFType(UBound(arrFType))) ' Case "html": ' Case "htm" : ' Case "jpg" : ' Case "jpeg": ' Case "bmp" : ' Case "gif" : ' Case "png": ' Case Else: ' 'Response.Write("2") ' Server.Transfer("/404.html") ' Response.End ' End Select Dim tPath:tPath="" '文件夹操作 For i=1 To Ubound(RemoteFileUrlU) Step 1 If i<>Ubound(RemoteFileUrlU) Then If(Not IsFolder(tPath&RemoteFileUrlU(i)))Then If i=1 Then Call CreateFolder(RemoteFileUrlU(i)) tPath=tPath&RemoteFileUrlU(i)&"/" Else Call CreateFolder(tPath&RemoteFileUrlU(i)) tPath=tPath&RemoteFileUrlU(i)&"/" End If Else tPath=tPath&RemoteFileUrlU(i)&"/" End If End If Next 'Set Retrieval = Server.CreateObject("Microsoft.XMLHTTP") With Retrieval .Open "GET", mainUrl&RemoteFileUrl, False, "", "" .Send GetRemoteData = .ResponseBody End With SaveFileName = SaveFilePaths Set Retrieval = Nothing Set Ads = Server.CreateObject("Adodb.Stream") With Ads .Type = 1 .Open .Write GetRemoteData .SaveToFile Server.MapPath(SaveFileName),2 .Cancel .Close End With Set Ads = Nothing SaveGetFile = SaveFileName End Function Function IsFolder(Folder) If FSO.FolderExists(Server.MapPath(Folder)) Then IsFolder = True Else IsFolder = False End If End Function Function CreateFolder(fldr) Dim f Set f = FSO.CreateFolder(Server.MapPath(fldr)) CreateFolder = f.Path Set f=nothing End Function Function ts(str) Response.Write(str) Response.End End Function Function ReplaceTest(patrn,str1,replStr) Dim regEx Set regEx = New RegExp regEx.Pattern = patrn regEx.IgnoreCase = True regEx.Global = True ReplaceTest = regEx.Replace(str1,replStr) End Function If Err Then Err.Clear Server.Transfer("/404.html") Response.End End If '转向抓取过来的资源 'Response.Write("3") Server.Transfer(re_url) Response.End %> |
View Details