|
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
在执行git pull的时候,提示当前branch没有跟踪信息:
|
1 2 3 |
git pull There is no tracking information for the current branch. Please specify which branch you want to merge with. |
对于这种情况有两种解决办法,就比如说要操作master吧,一种是直接指定远程master:
|
1 |
git pull origin master |
另外一种方法就是先指定本地master到远程的master,然后再去pull:
|
1 2 |
git branch --set-upstream-to=origin/master master git pull |
这样就不会再出现“There is no tracking information for the current branch”这样的提示了。 ———————————————— 版权声明:本文为CSDN博主「K.Sun」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/sinat_36246371/article/details/79738782
View Details宝塔面板如何卸载?宝塔面板是国内一款简洁易用的服务器管理面板,而有时候我们出于各种各样的原因可能需要卸载宝塔。面板既然能够安装,当然也可以卸载,下面我们介绍下卸载方法。 windows面板卸载 1.打开宝塔面板windows版安装目录,路径为:面板安装数据盘:\BtSoft\ServerAdmin 2.运行 UnInstall.exe 开始面板卸载 3.最后使用注册表清理软件或者360清理,清理注册表才可以清除服务文件。在卸载完成后,重启服务器以确保卸载干净。 linux面板卸载方法 一、脚本卸载 1.你需要先在面板中将通过面板安装的所有软件卸载,如 nginx、mysql、php 等等,然后,进入 SSH 命令行,输入以下命令: /etc/init.d/bt stop && rm -f /etc/init.d/bt && rm -rf /www/server/panel 2.或者脚本卸载更暴力一点的直接是都卸载,命令如下:
|
1 2 |
wget http://download.bt.cn/install/bt-uninstall.sh sh bt-uninstall.sh |
二、后续解决 虽然卸载了面板及面板环境,可是系统还是会残留一些文件,比如 www 目录,网站文件。为防止安装别的面时出现一些错误,我们可以用命令:rm –rf www 强制删除 www 文件夹。 以上是关于宝塔面板如何卸载的介绍,安装宝塔面板需要确保纯净系统安装,西部数码云服务器提供预装好宝塔面板的系统模板,可直接安装使用,如需安装请点击 https://www.west.cn/cloudhost/linux.asp from:https://www.west.cn/docs/58109.html
View Details我遇到了 Your project is not referencing the “.NETFramework,Version=4.5” framework. Add a reference to “.NETFramework,Version=4.5” in the “frameworks” section of your project.json, and then re-run NuGet restore. 怎么弄都没法解决,我尝试了git撤销更改也无法解决,最后解决方法:删除/obj文件。 来自stackoverflow ———————————————— 版权声明:本文为CSDN博主「迷惘小书童」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/m0_37080285/article/details/90206495
View Details以我们家庭好医.netcore项目做个示例,来看看怎么进一步优化Docker镜像的大小。 这里以先编译再做镜像的方法为示例,当然你也可以把编译部分也写进Dockerfile里。 0.先来看看编译后的项目文件大小:39.2MB 1.先看一下VS2019默认Dockerfile生成的镜像 先上Dockerfile
|
1 2 3 4 5 6 7 8 |
FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base WORKDIR /app EXPOSE 5000 FROM base AS final WORKDIR /app COPY . . ENTRYPOINT ["dotnet", "JTHY.Web.dll"] |
看看生成的镜像大小:265MB 2.用大家常用的slim镜像试试 Dockerfile
|
1 2 3 4 5 6 7 8 |
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base WORKDIR /app EXPOSE 5000 FROM base AS final WORKDIR /app COPY /. /app ENTRYPOINT ["dotnet", "JTHY.Web.dll"] |
镜像大小还是265MB,并没有变小。 3.用大家不常用的alpine镜像来优化 Dockerfile
|
1 2 3 4 5 6 7 8 |
ROM mcr.microsoft.com/dotnet/aspnet:3.1-alpine AS base WORKDIR /app EXPOSE 5000 FROM base AS final WORKDIR /app COPY /. /app ENTRYPOINT ["dotnet", "JTHY.Web.dll"] |
再来看看镜像大小:146MB,是不是很神奇~
View Details撤销push 1. 执行 git log查看日志,获取需要回退的版本号 2. 执行 git reset –-soft <版本号> ,如 git reset --soft 4f5e9a90edeadcc45d85f43bd861a837fa7ce4c7 ,重置至指定版本的提交,达到撤销提交的目的 然后执行 git log 查看 此时,已重置至指定版本的提交,log中已经没有了需要撤销的提交 git reset 命令分为两种: git reset –-soft 与 git reset –-hard ,区别是: 前者表示只是改变了HEAD的指向,本地代码不会变化,我们使用git status依然可以看到,同时也可以git commit提交。后者直接回改变本地源码,不仅仅指向变化了,代码也回到了那个版本时的代码。 3. 执行 git push origin 分支名 –-force ,强制提交当前版本号。 至此,撤销push提交完成。 撤销commit 1. 执行 git log 查看需要撤销的commit的前面一个提交版本的id; 2. 执行 git reset --hard commit_id ,该commit_id为需要撤销的commit的提交的前面一个提交的版本,即需要恢复到的提交的id,重置至指定版本的提交,达到撤销提交的目的 3. 执行 git log 查看,commit提交已撤销 from:https://www.cnblogs.com/chaoxiZ/p/9714085.html
View Details微服务规范 前后端分离 数据库避免大量联合查询 服务设计无状态化 服务拆分最多三层,两次调用: 底层:基础服务层 中间层:组合服务层 上层:对外接口层 提供微服务关系图 统一维护微服务相互调用接口 配置统一到apollo 建议设计独立适配微服务以便调用外部服务 接口实现需幂等 定时任务建议实现在统一的单独微服务中,调用其它微服务接口来实现业务。否则和其它微服务实例一起部署的任务须加锁控制,以避免多实例冲突; 持续集成单元测试、接口测试 容器化并自动构建镜像、kubernetes部署 技术选型: 网关:spring cloud gateway 注册中心: consul 调用: feign 负载均衡:ribbon 熔断限流降级:hystrix 监控:cat, hystrix+trubine 容器:docker+kubernetes 微服务实战 环境准备 玩转Docker 服务注册发现Consul起步 实战课程 微服务概览 大话微服务 Provider微服务实战 Consumer微服务实战 Spring Cloud Gateway实战 Spring Cloud Gateway之Filter实战 微服务之网关——spring cloud gateway简单实践 掌医开放平台gateway服务设计及使用手册 契约测试实战 微服务监控-CAT Sleuth+Zipkin调用链监控实战 Hystrix熔断限流降级&Turbine API监控实战 微服务横向热扩展和自定义负载均衡策略 spring cloud gateway聚合swagger K8S创建服务实践小记 Google Jib:Java容器镜像构建新工具 微服务feign调用失败排查问题思路 微服务demo 微服务demo gitlab仓库
View Details此前的 Java 社区报告曾指出,Java 8 仍是开发人员使用的主要版本,新版本并未“得宠”。但 Snyk 近期发布的 JVM Ecosystem Report 2021 则指出,开发人员已经逐渐从 Java 8 迁移到了 Java 11。 JVM Ecosystem Report 2021 展示了关于 JVM 生态系统状态的最大年度调查的结果。该调查在 2021 年 2 月和 3 月的六周时间里进行,收集了来自 2000 多名 Java 开发者的回复。 调查结果显示,有 44.1% 的受访者在生产中使用免费的 AdoptOpenJDK 发行版。但 Oracle 仍然是市场上的重要参与者,其 OpenJDK 构建占 28%,商业 Oracle JDK 占 23%。 40% 的调查参与者在生产中使用了一个以上的 Java 版本。升级到 8 版本以上的人也比预料的要多。目前,有 61.5% 的人在生产中使用 Java 11,近 12% 的人使用最新版本,即调查期间的 Java 15。 Snyk 方面在报告中指出,这表明开发人员确实将他们的 Java 版本升级到了 Java 8 以上的版本,有关大多数 Java 开发人员都乐于使用 Java 8 的现象似乎正在慢慢瓦解。不过值得注意的是,仍有一半的 Java 11 用户(目前使用最多的版本)在他们的生产堆栈中使用 Java 8。 从长远来看,虽然 JVM 语言的种类在过去几年中有所增长,但 Java 仍然是最受欢迎的语言。超过 90% 的开发者使用 Java;Kotlin 次之,为 17.7%。 而 JetBrains IntelliJ IDEA […]
View Details参考文档 https://www.cnblogs.com/htsboke/p/10956807.html https://www.cnblogs.com/lenmom/p/8510572.html https://www.cnblogs.com/yaopengfei/p/9479268.html 在WebApi项目中使用AutoFac,结构如下: 首先在Api项目当中引用AutoFac包,如下图所示: 仓储类:
|
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 |
public interface IUsersRepository { int GetUserIsExists(UsersEntity criteria); } public class UsersRepository : IUsersRepository { Logger log = LogManager.GetLogger("UsersRepository"); /// <summary> /// 获取用户是否存在 /// </summary> /// <param name="criteria"></param> /// <returns></returns> public int GetUserIsExists(UsersEntity criteria) { string sql = "。。。。"; try { //查询sql代码,此处省略。。。。 } catch (Exception ex) { log.Fatal(ex, "获取用户是否存在异常:{0},SQL:{1}", ex.Message, sql); return 0; } } } |
服务类:
|
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 |
//接口 public interface IUsersService { int GetUserIsExists(UsersEntity criteria); } //实现类 public class UsersService : IUsersService { private readonly IUsersRepository _usersrepository; public UsersService(IUsersRepository usersrepository) //通过构造函数注入 { _usersrepository = usersrepository; } /// <summary> /// 获取用户是否存在 /// </summary> /// <param name="criteria"></param> /// <returns></returns> public int GetUserIsExists(UsersEntity criteria) { return _usersrepository.GetUserIsExists(criteria); } } |
在Api接口项目中创建一个AutoFac工具类:AutofacUtil.cs
|
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 |
public class AutofacUtil { private static IContainer _container; public static void ConfigureContainer() { #region AutoFac IOC容器 var builder = new ContainerBuilder(); try { //builder.RegisterControllers(Assembly.GetCallingAssembly()); //注册mvc控制器 需要引用package Autofac.Mvc //builder.RegisterApiControllers(Assembly.GetExecutingAssembly()).PropertiesAutowired(); //支持Api控制器属性注入 builder.RegisterApiControllers(Assembly.GetCallingAssembly()); //注册所有api控制器 构造函数注入 需要引用package Autofac.WebApi //注册程序集 #region Service var assemblysServices = Assembly.Load("WebApi.Service"); builder.RegisterAssemblyTypes(assemblysServices) .AsImplementedInterfaces() .InstancePerDependency(); #endregion #region Repository var assemblysRepository = Assembly.Load("WebApi.Repository"); builder.RegisterAssemblyTypes(assemblysRepository) .AsImplementedInterfaces() .InstancePerDependency(); #endregion _container = builder.Build(); //创建依赖注入 //设置MVC依赖注入 //DependencyResolver.SetResolver(new AutofacDependencyResolver(_container)); //设置WebApi依赖注入 GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(_container); } catch (Exception ex) { throw new Exception(ex.Message + "\n" + ex.InnerException); } #endregion } /// <summary> /// 从Autofac容器获取对象 /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public static T GetFromFac<T>() { return _container.Resolve<T>(); } } |
在 Global.asax.cs 全局中注册一下:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
public class WebApiApplication : System.Web.HttpApplication { protected void Application_Start() { AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); //AutoFac 注册 AutofacUtil.ConfigureContainer(); } } |
最后在接口中使用:
|
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 |
public class UsersController : ApiController { private readonly IUsersService _usersService; public UsersController(IUsersService usersService) //使用构造函数注入 { _usersService = usersService; } /// <summary> /// 获取用户是否存在 /// </summary> /// <param name="username"></param> /// <param name="password"></param> /// <returns></returns> [HttpPost] public IHttpActionResult GetUserIsExists(string username, string password) { //验证是否存在当前用户 var obModel = new UsersEntity() { Username = username, Password = Encryption.MD5(password) }; var getresult = _usersService.GetUserIsExists(obModel); return Json(new { isexists = getresult > 0 }); } } |
测试结果: 最后:如果出现 未将对象引用的实例 的错误,检查一下是否引用相应的dll程序集了。 from:https://www.cnblogs.com/peterzhang123/p/12808922.html
View Details