首页 文章 精选 留言 我的

精选列表

搜索[asp],共1555篇文章
优秀的个人博客,低调大师

ASP.NET Core on K8S深入学习(3-2)DaemonSet与Job

​ 一、DaemonSet 1.1 DaemonSet是个啥? Deployment的部署可以指定副本Pod分布在多个Node节点上,且每个Node都可以运行多个Pod副本。而DaemonSet呢,它倔强地保证在每个Node上都只运行一个Pod副本。 回想一下项目经历,有哪些场景满足这个特质呢?是不是一些集群的日志、监控或者其他系统管理应用? 日志收集,比如fluentd,logstash等 系统监控,比如Prometheus Node Exporter,collectd,New Relic agent,Ganglia gmond等 系统程序,比如kube-proxy,kube-dns,glusterd,ceph等 Prometheus Node Exporter Dashboard 1.2 K8S中的DaemonSet 在K8S中,就有一些默认的使用DaemonSet方式运行的系统组件,比如我们可以通过下面一句命令查看: kubectl get daemonset --namespace=kube-system 可以看到,kube-flannel-ds 和 kube-proxy 是K8S以DaemonSet方式运行的系统组件,分别为K8S集群负责提供网络连接支持和代理支持,这里不深入讨论它们的详细情况,只需要了解它们负责什么就可以了。在通过查看Pod副本,看看各个节点的分布情况: kubectl get pod --namespace=kube-system -o wide 可以看到,它们两分布在各个Node节点上(这里是我的K8S集群中的所有节点了),且每个节点上只有一个Pod副本。 1.3DaemonSet的创建和运行 同之前的创建资源方式一样,仍然采用通过YAML配置文件的方式进行创建,只需要指定kind: DaemonSet即可: apiVersion: apps/v1 kind: DaemonSet 这里我们以Prometheus Node Exporter为例演示一下如何运行我们自己的DaemonSet。 _PS:_Prometheus是流行的系统监控方案,而Node Exporter负责收集节点上的metrics监控数据,并将数据推送给Prometheus。Prometheus则负责存储这些数据,Grafana最终将这些数据通过网页以图形的形式展现给用户。 下面是yaml配置文件对于DaemonSet资源清单的定义: apiVersion: apps/v1 kind: DaemonSet metadata: name: node-exporter-daemonset namespace: agent spec: selector: matchLabels: app: prometheus template: metadata: labels: app: prometheus spec: hostNetwork: true containers: - name: node-exporter image: prom/node-exporter imagePullPolicy: IfNotPresent command: - /bin/node_exporter - --path.procfs - /host/proc - --path.sysfs - /host/sys - --collector.filesystem.ignored-mount-points - ^/(sys|proc|dev|host|etc)($|/) volumeMounts: - name: proc mountPath: /host/proc - name: sys mountPath: /host/sys - name: root mountPath: /rootfs volumes: - name: proc hostPath: path: /proc - name: sys hostPath: path: /sys - name: root hostPath: path: / 这里暂且不纠结其中的配置内容,包括Host网络、容器启动命令以及Volume,后面会专题介绍。 同样,通过kubectl创建资源: kubectl apply -f node-exporter.yaml 然后,通过kubectl查看Pod分布情况: 可以看出,我们的Prometheus Node Exporter部署成功,且分别在两个Node节点都只部署了一个Pod副本。 二、Job 2.1 关于Job 对于ReplicaSet、Deployment、DaemonSet等类型的控制器而言,它希望Pod保持预期数目并且持久运行下去,除非用户明确删除,否则这些对象一直存在,因此可以说他们说持久服务型任务的。 对于非耐久性任务,比如压缩文件,任务完成后,Pod需要结束运行,不需要Ppod继续保持在系统中,这个时候就要用到Job。因此也可以说,Job是对ReplicaSet、Deployment、DaemonSet等持久性控制器的补充。 2.2 Job的创建与运行 同之前的创建资源方式一样,仍然采用通过YAML配置文件的方式进行创建,需要指定apiVersioin: batch 以及 kind: Job即可: apiVersion: batch/v1 (1)第一个Job 这里我们以一个简单的小Job为例,看看一个简单的Job:当Job启动后,只运行一个Pod,Pod运行结束后整个Job也就立刻结束。 apiVersion: batch/v1 kind: Job metadata: name: edc-job-hello-job namespace: jobs spec: template: metadata: labels: app: edc-job-hello-job spec: containers: - name: hello-job image: busybox imagePullPolicy: IfNotPresent command: ["echo", "hello edison's k8s job!"] restartPolicy: Never 这里需要注意的是,对Job而言,其restartPolicy只能为Never或者OnFailure,这也是它与其他控制器的差别(如Deployment控制器还允许设置为Always)。这个Job要执行的任务也很简单,就是输出一段话“hello edison's k8s job!”就结束其生命了。 _PS:_这里用到了一个busybox的镜像,busybox是一个软件工具箱,里边集成了Linux中几百个常用的Linux命令以及工具。如果我们只需要一个小型的Linux运行环境跑命令,完全可以使用这个busybox镜像,而不用拉取一个CentOS镜像。 通过查看Job运行情况可以知道,其运行结束就结束了,如下图所示,变成了Completed状态。 kubectl get pod -n jobs 还可以通过查看Log看看这个Job留下的足迹: kubectl get pod -n jobs --show-all kubectl logs edc-job-hello-job-whcts (2)并行Job 如果希望能够同时并行运行多个Pod以提高Job的执行效率,Job提供了一个贴心的配置:parallesim。例如下面的配置,我们将上面的小Job改为并行运行的Pod数量设置为3。 apiVersion: batch/v1 kind: Job metadata: name: edc-job-hello-job namespace: jobs spec: parallelism: 3 template: metadata: labels: app: edc-job-hello-job spec: containers: - name: hello-job image: busybox imagePullPolicy: IfNotPresent command: ["echo", "hello edison's k8s job!"] restartPolicy: OnFailure _PS:_默认parallelism值为1 使用上面的配置文件创建了资源后,通过以下命令查看验证: kubectl get job -n jobs kubectl get pod -o wide -n jobs 可以看出,Job一共启动了3个Pod,都是同时结束的(可以看到三个Pod的AGE都是相同的)。 此外,Job还提供了一个completions属性使我们可以设置Job完成的Pod总数,还是上面的例子: apiVersion: batch/v1 kind: Job metadata: name: edc-job-hello-job namespace: jobs spec: parallelism: 3 completions: 6 template: metadata: labels: app: edc-job-hello-job spec: containers: - name: hello-job image: busybox imagePullPolicy: IfNotPresent command: ["echo", "hello edison's k8s job!"] restartPolicy: OnFailure _PS:_默认completions也为1 上面的配置意思就是:每次运行3个Pod,直到总共有6个Pod就算成功完成。同样通过命令验证一下: 可以看到,状态和AGE都符合预期,第一批3个Pod的AGE为12s,第二批3个Pod的AGE为14s。 2.3 CronJob的创建与运行 我们都知道在Linux中,Cron程序可以定时执行任务,而在K8S中也提供了一个CronJob帮助我们实现定时任务。 继续以上面的例子,我们增加一些配置: apiVersion: batch/v1beta1 kind: CronJob metadata: name: edc-cron-job namespace: jobs spec: schedule: "*/1 * * * *" jobTemplate: spec: template: spec: containers: - name: cron-job image: busybox imagePullPolicy: IfNotPresent command: ["echo", "hello edison's k8s cron job!"] restartPolicy: OnFailure 上面加粗的配置是CronJob的独有配置,需要注意的是schedule,它的格式和Linux Cron一样,这里的"*/1 * * * *"代表每一分钟启动执行一次。对于CronJob,它需要的是jobTemplate来定义Job的模板。 同样,隔几分钟之后,通过命令来验证一下: 可以看到,在过去的三分钟里,每一分钟都启动了一个Pod,符合预期。 三、小结 Deployment可以满足我们大部分时候的应用部署(无状态服务类容器),但是针对一些特殊的场景应用,Deployment就无法胜任了。比如日志收集、系统监控等场景,就可以使用今天介绍的DaemonSet。又比如批处理定时任务,则可以使用今天介绍的Job/CronJob。 参考资料 (1)CloudMan,《每天5分钟玩转Kubernetes》 (2)李振良,《一天入门Kubernets教程》 (3)马哥(马永亮),《Kubernetes快速入门》 (4)阿龙,《Kubernetes系列-07.Pod控制器详解》 (5)elvis,《K8S-Job与CronJob的使用》 (6)五星上炕,《Kubernetes之Job详解》

优秀的个人博客,低调大师

2.1命令行和JSON的配置「深入浅出ASP.NET Core系列」

希望给你3-5分钟的碎片化学习,可能是坐地铁、等公交,积少成多,水滴石穿,谢谢关注。 命令行配置 1.新建控制台项目 2.nuget引入microsoft.aspnetcore.all 这里要注意版本号必须和dotnetcore兼容 3.编码 3.1.引入Microsoft.Extensions.Configuration; 3.2.AddCommandLine() 添加到命令行 3.3.AddInMemoryCollection 添加到内存当中 3.4.代替string.format的新语法糖:$"age:{configuration["age"]}" 4.查看结果 直接运行 powershell下运行 JSON配置 2.1新建配置文件student.json 编写json配置内容 2.2引入json,AddJsonFile() 2.3确保json文件生成到bin目录下 右键进入文件属性 设置始终复制和生成操作为内容 2.4编码读取配置 我是.NET架构师张飞洪,入行10年有余,人不堪其忧,吾不改其乐,谢谢您关注我的头条号。

优秀的个人博客,低调大师

(4)学习笔记 ) ASP.NET CORE微服务 Micro-Service ---- Consul服务发现和消费

上一章说了 Consul服务注册 现在我要连接上Consul里面的服务 请求它们的API接口 应该怎么做呢? 1.找Consul要一台你需要的服务器 1.1 获取Consul下的所有注册的服务 using (var consulClient = new ConsulClient(c => c.Address = new Uri("http://127.0.0.1:8500"))) { var services = consulClient.Agent.Services().Result.Response; foreach(var service in services.Values) { Console.WriteLine($"id={service.ID},name={service.Service},ip={service.Address},port={service.Port}"); } } 1.2 随机取一个Name为MsgService的服务 下面的代码使用当前 TickCount 进行取模的方式达到随机获取一台服务器实例的效果,这叫做“客户端负载均衡”: using (var consulClient = new ConsulClient(c => c.Address = new Uri("http://127.0.0.1:8500"))) { var services = consulClient.Agent.Services().Result.Response.Values.Where(s => s.Service.Equals("MsgService", StringComparison.OrdinalIgnoreCase)); if(!services.Any()) { Console.WriteLine("找不到服务的实例"); } else { var service = services.ElementAt(Environment.TickCount%services.Count()); Console.WriteLine($"{service.Address}:{service.Port}"); } } 当然在一个毫秒之类会所有请求都压给一台服务器,基本就够用了。也可以自己写随机、轮询等客户端负载均衡算法,也可以自己实现按不同权重分配(注册时候 Tags 带上配置、权重等信息)等算法。 2.请求服务器的接口 你拿到了http地址 难道还不会请求接口么 找个httphelper 直接请求就好了 如果还是不会 就来群里问吧 群号:608188505 给大家上一个 我常用的httphelper 可能被我该的不像样了 不过相信大家都会用 不会的话 来群里找我吧。 1 using System; 2 using System.Collections.Generic; 3 using System.Diagnostics; 4 using System.IO; 5 using System.IO.Compression; 6 using System.Linq; 7 using System.Net; 8 using System.Net.Security; 9 using System.Runtime.InteropServices; 10 using System.Security.Cryptography.X509Certificates; 11 using System.Text; 12 using System.Text.RegularExpressions; 13 using System.Threading.Tasks; 14 15 namespace ClientApp 16 {/// <summary> 17 /// Http连接操作帮助类 18 /// </summary> 19 public class HttpHelper 20 { 21 private const int ConnectionLimit = 100; 22 //编码 23 private Encoding _encoding = Encoding.Default; 24 //浏览器类型 25 private string[] _useragents = new string[]{ 26 "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36", 27 "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)", 28 "Mozilla/5.0 (Windows NT 6.1; rv:36.0) Gecko/20100101 Firefox/36.0", 29 "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20130401 Firefox/31.0" 30 }; 31 32 private String _useragent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36"; 33 //接受类型 34 private String _accept = "text/html, application/xhtml+xml, application/xml, */*"; 35 //超时时间 36 private int _timeout = 30 * 1000; 37 //类型 38 private string _contenttype = "application/x-www-form-urlencoded"; 39 //cookies 40 private String _cookies = ""; 41 //cookies 42 private CookieCollection _cookiecollection; 43 //custom heads 44 private Dictionary<string, string> _headers = new Dictionary<string, string>(); 45 46 public HttpHelper() 47 { 48 _headers.Clear(); 49 //随机一个useragent 50 _useragent = _useragents[new Random().Next(0, _useragents.Length)]; 51 //解决性能问题? 52 ServicePointManager.DefaultConnectionLimit = ConnectionLimit; 53 } 54 55 public void InitCookie() 56 { 57 _cookies = ""; 58 _cookiecollection = null; 59 _headers.Clear(); 60 } 61 62 /// <summary> 63 /// 设置当前编码 64 /// </summary> 65 /// <param name="en"></param> 66 public void SetEncoding(Encoding en) 67 { 68 _encoding = en; 69 } 70 71 /// <summary> 72 /// 设置UserAgent 73 /// </summary> 74 /// <param name="ua"></param> 75 public void SetUserAgent(String ua) 76 { 77 _useragent = ua; 78 } 79 80 public void RandUserAgent() 81 { 82 _useragent = _useragents[new Random().Next(0, _useragents.Length)]; 83 } 84 85 public void SetCookiesString(string c) 86 { 87 _cookies = c; 88 } 89 90 /// <summary> 91 /// 设置超时时间 92 /// </summary> 93 /// <param name="sec"></param> 94 public void SetTimeOut(int msec) 95 { 96 _timeout = msec; 97 } 98 99 public void SetContentType(String type) 100 { 101 _contenttype = type; 102 } 103 104 public void SetAccept(String accept) 105 { 106 _accept = accept; 107 } 108 109 /// <summary> 110 /// 添加自定义头 111 /// </summary> 112 /// <param name="key"></param> 113 /// <param name="ctx"></param> 114 public void AddHeader(String key, String ctx) 115 { 116 //_headers.Add(key,ctx); 117 _headers[key] = ctx; 118 } 119 120 /// <summary> 121 /// 清空自定义头 122 /// </summary> 123 public void ClearHeader() 124 { 125 _headers.Clear(); 126 } 127 128 /// <summary> 129 /// 获取HTTP返回的内容 130 /// </summary> 131 /// <param name="response"></param> 132 /// <returns></returns> 133 private String GetStringFromResponse(HttpWebResponse response) 134 { 135 String html = ""; 136 try 137 { 138 Stream stream = response.GetResponseStream(); 139 StreamReader sr = new StreamReader(stream, Encoding.UTF8); 140 html = sr.ReadToEnd(); 141 142 sr.Close(); 143 stream.Close(); 144 } 145 catch (Exception e) 146 { 147 Trace.WriteLine("GetStringFromResponse Error: " + e.Message); 148 } 149 150 return html; 151 } 152 153 /// <summary> 154 /// 检测证书 155 /// </summary> 156 /// <param name="sender"></param> 157 /// <param name="certificate"></param> 158 /// <param name="chain"></param> 159 /// <param name="errors"></param> 160 /// <returns></returns> 161 private bool CheckCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) 162 { 163 return true; 164 } 165 166 /// <summary> 167 /// 发送GET请求 168 /// </summary> 169 /// <param name="url"></param> 170 /// <returns></returns> 171 public String HttpGet(String url) 172 { 173 return HttpGet(url, url); 174 } 175 176 177 /// <summary> 178 /// 发送GET请求 179 /// </summary> 180 /// <param name="url"></param> 181 /// <param name="refer"></param> 182 /// <returns></returns> 183 public String HttpGet(String url, String refer) 184 { 185 String html; 186 try 187 { 188 ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckCertificate); 189 HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url); 190 request.UserAgent = _useragent; 191 request.Timeout = _timeout; 192 request.ContentType = _contenttype; 193 request.Accept = _accept; 194 request.Method = "GET"; 195 request.Referer = refer; 196 request.KeepAlive = true; 197 request.AllowAutoRedirect = true; 198 request.UnsafeAuthenticatedConnectionSharing = true; 199 request.CookieContainer = new CookieContainer(); 200 //据说能提高性能 201 //request.Proxy = null; 202 if (_cookiecollection != null) 203 { 204 foreach (Cookie c in _cookiecollection) 205 { 206 c.Domain = request.Host; 207 } 208 209 request.CookieContainer.Add(_cookiecollection); 210 } 211 212 foreach (KeyValuePair<String, String> hd in _headers) 213 { 214 request.Headers[hd.Key] = hd.Value; 215 } 216 217 HttpWebResponse response = (HttpWebResponse)request.GetResponse(); 218 html = GetStringFromResponse(response); 219 if (request.CookieContainer != null) 220 { 221 response.Cookies = request.CookieContainer.GetCookies(request.RequestUri); 222 } 223 224 if (response.Cookies != null) 225 { 226 _cookiecollection = response.Cookies; 227 } 228 if (response.Headers["Set-Cookie"] != null) 229 { 230 string tmpcookie = response.Headers["Set-Cookie"]; 231 _cookiecollection.Add(ConvertCookieString(tmpcookie)); 232 } 233 234 response.Close(); 235 return html; 236 } 237 catch (Exception e) 238 { 239 Trace.WriteLine("HttpGet Error: " + e.Message); 240 return String.Empty; 241 } 242 } 243 244 /// <summary> 245 /// 获取MINE文件 246 /// </summary> 247 /// <param name="url"></param> 248 /// <returns></returns> 249 public Byte[] HttpGetMine(String url) 250 { 251 Byte[] mine = null; 252 try 253 { 254 ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckCertificate); 255 HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url); 256 request.UserAgent = _useragent; 257 request.Timeout = _timeout; 258 request.ContentType = _contenttype; 259 request.Accept = _accept; 260 request.Method = "GET"; 261 request.Referer = url; 262 request.KeepAlive = true; 263 request.AllowAutoRedirect = true; 264 request.UnsafeAuthenticatedConnectionSharing = true; 265 request.CookieContainer = new CookieContainer(); 266 //据说能提高性能 267 request.Proxy = null; 268 if (_cookiecollection != null) 269 { 270 foreach (Cookie c in _cookiecollection) 271 c.Domain = request.Host; 272 request.CookieContainer.Add(_cookiecollection); 273 } 274 275 foreach (KeyValuePair<String, String> hd in _headers) 276 { 277 request.Headers[hd.Key] = hd.Value; 278 } 279 280 HttpWebResponse response = (HttpWebResponse)request.GetResponse(); 281 Stream stream = response.GetResponseStream(); 282 MemoryStream ms = new MemoryStream(); 283 284 byte[] b = new byte[1024]; 285 while (true) 286 { 287 int s = stream.Read(b, 0, b.Length); 288 ms.Write(b, 0, s); 289 if (s == 0 || s < b.Length) 290 { 291 break; 292 } 293 } 294 mine = ms.ToArray(); 295 ms.Close(); 296 297 if (request.CookieContainer != null) 298 { 299 response.Cookies = request.CookieContainer.GetCookies(request.RequestUri); 300 } 301 302 if (response.Cookies != null) 303 { 304 _cookiecollection = response.Cookies; 305 } 306 if (response.Headers["Set-Cookie"] != null) 307 { 308 _cookies = response.Headers["Set-Cookie"]; 309 } 310 311 stream.Close(); 312 stream.Dispose(); 313 response.Close(); 314 return mine; 315 } 316 catch (Exception e) 317 { 318 Trace.WriteLine("HttpGetMine Error: " + e.Message); 319 return null; 320 } 321 } 322 323 /// <summary> 324 /// 发送POST请求 325 /// </summary> 326 /// <param name="url"></param> 327 /// <param name="data"></param> 328 /// <returns></returns> 329 public String HttpPost(String url, String data) 330 { 331 return HttpPost(url, data, url,null); 332 } 333 334 /// <summary> 335 /// 发送POST请求 336 /// </summary> 337 /// <param name="url"></param> 338 /// <param name="data"></param> 339 /// <param name="refer"></param> 340 /// <returns></returns> 341 public String HttpPost(String url, String data, String refer,string cookie) 342 { 343 String html; 344 try 345 { 346 ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckCertificate); 347 HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url); 348 request.UserAgent = _useragent; 349 request.Timeout = _timeout; 350 request.Referer = refer; 351 request.ContentType = _contenttype; 352 request.Accept = _accept; 353 request.Method = "POST"; 354 request.KeepAlive = true; 355 request.AllowAutoRedirect = true; 356 357 request.CookieContainer = new CookieContainer(); 358 if (!string.IsNullOrEmpty(cookie)) 359 { 360 _cookiecollection = this.ConvertCookieString(cookie); 361 } 362 //据说能提高性能 363 request.Proxy = null; 364 365 if (_cookiecollection != null) 366 { 367 foreach (Cookie c in _cookiecollection) 368 { 369 c.Domain = request.Host; 370 if (c.Domain.IndexOf(':') > 0) 371 c.Domain = c.Domain.Remove(c.Domain.IndexOf(':')); 372 } 373 request.CookieContainer.Add(_cookiecollection); 374 } 375 376 foreach (KeyValuePair<String, String> hd in _headers) 377 { 378 request.Headers[hd.Key] = hd.Value; 379 } 380 byte[] buffer = _encoding.GetBytes(data.Trim()); 381 request.ContentLength = buffer.Length; 382 request.GetRequestStream().Write(buffer, 0, buffer.Length); 383 request.GetRequestStream().Close(); 384 385 HttpWebResponse response = (HttpWebResponse)request.GetResponse(); 386 html = GetStringFromResponse(response); 387 if (request.CookieContainer != null) 388 { 389 response.Cookies = request.CookieContainer.GetCookies(request.RequestUri); 390 } 391 if (response.Cookies != null) 392 { 393 _cookiecollection = response.Cookies; 394 } 395 if (response.Headers["Set-Cookie"] != null) 396 { 397 string tmpcookie = response.Headers["Set-Cookie"]; 398 _cookiecollection.Add(ConvertCookieString(tmpcookie)); 399 } 400 401 response.Close(); 402 return html; 403 } 404 catch (Exception e) 405 { 406 Trace.WriteLine("HttpPost Error: " + e.Message); 407 return String.Empty; 408 } 409 } 410 411 412 public string UrlEncode(string str) 413 { 414 StringBuilder sb = new StringBuilder(); 415 byte[] byStr = _encoding.GetBytes(str); 416 for (int i = 0; i < byStr.Length; i++) 417 { 418 sb.Append(@"%" + Convert.ToString(byStr[i], 16)); 419 } 420 421 return (sb.ToString()); 422 } 423 424 /// <summary> 425 /// 转换cookie字符串到CookieCollection 426 /// </summary> 427 /// <param name="ck"></param> 428 /// <returns></returns> 429 private CookieCollection ConvertCookieString(string ck) 430 { 431 CookieCollection cc = new CookieCollection(); 432 string[] cookiesarray = ck.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); 433 for (int i = 0; i < cookiesarray.Length; i++) 434 { 435 string[] cookiesarray_2 = cookiesarray[i].Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); 436 for (int j = 0; j < cookiesarray_2.Length; j++) 437 { 438 string[] cookiesarray_3 = cookiesarray_2[j].Trim().Split("=".ToCharArray()); 439 if (cookiesarray_3.Length == 2) 440 { 441 string cname = cookiesarray_3[0].Trim(); 442 string cvalue = cookiesarray_3[1].Trim(); 443 if (cname.ToLower() != "domain" && cname.ToLower() != "path" && cname.ToLower() != "expires") 444 { 445 Cookie c = new Cookie(cname, cvalue); 446 cc.Add(c); 447 } 448 } 449 } 450 } 451 452 return cc; 453 } 454 455 456 public void DebugCookies() 457 { 458 Trace.WriteLine("**********************BEGIN COOKIES*************************"); 459 foreach (Cookie c in _cookiecollection) 460 { 461 Trace.WriteLine(c.Name + "=" + c.Value); 462 Trace.WriteLine("Path=" + c.Path); 463 Trace.WriteLine("Domain=" + c.Domain); 464 } 465 Trace.WriteLine("**********************END COOKIES*************************"); 466 } 467 468 } 469 } Httphelper 小哥哥 小姐姐们 如果本篇文章对你们有帮助的话 就点点右下角的推荐吧 0.0 现在的努力只是为了更好的将来,将来你一定不会后悔你现在的努力。一起加油吧!!! C#/.NetCore技术交流群:608188505欢迎加群交流 如果您认为这篇文章还不错或者有所收获,您可以点击右下角的【推荐】按钮精神支持,因为这种支持是我继续写作,分享的最大动力!

优秀的个人博客,低调大师

asp.net mvc5 分析器错误消息: 未能加载类型“XXX.MvcApplication”

描述 今天忽然碰到一个这个错误: “/”应用程序中的服务器错误。 分析器错误 说明:在分析向此请求提供服务所需资源时出错。请检查下列特定分析错误详细信息并适当地修改源文件。分析器错误消息:未能加载类型“XX.MvcApplication”。源错误: 行 1: <%@ Application Codebehind="Global.asax.cs" Inherits="XX.MvcApplication" Language="C#" %> 源文件:/global.asax 行:1 顿时懵逼,不知如何是好,果然是问题发生在自己身上的时候就会不知所措 ,教别人的时候说的头头是道。 思路 下面说说解决这类问题的思路 首先看一下提示,未能加载类型“XX.MvcApplication”,也就是找不到这个类型,源文件是 global.asax的第一行。 下一步,为什么会找不到呢?分析原因:第一、命名空间不同。可能修改了,不统一,所以找不到;第二、输出的位置改掉了,不在web.config文件所在目录的bin文件夹里面,导致网站启动的时候找不到相应的项目的dll 知道大概原因就好解决问题了,下次遇到这种黄色错误页,不要慌,先做深呼吸,然后看提示,参考这里说的思路尝试一下,基本就能解决大部分问题。 总结 mvc启动最开始运行 global.asax里面的类 MvcApplication 的 application_start 方法,在这里注册全局配置,基本上这个方法断点成功之后,说明项目的文件都没什么问题,出现什么问题,都能通过合理的断点去调试来发现解决问题。这次是启动失败了,那么首先应该检查文件,web.config在哪里,相应的dll又在哪里,齐不齐全,结合出错提示来排查问题。出现一个问题,然后深究它出现的原因,往往能够了解更身一层的原理,并且记忆更加深刻。如果要达到那种出现问题一看就知道什么原因的程度,要么遇到并解决过此类问题要么知道它背后的原理。而要进行这个学习提高经验,可以有如下做法:第一、找官网文档或者研究源码,弄懂原理,这种不经过大量实战还是不能很好掌握;第二、每出现一个问题就研究背后原理,次数多了,串起来也能逐渐完整,这种针对性强一点,要求每次都要弄懂原理而不仅仅是解决问题。最后,无论学习什么,要掌握并熟练这门技术,都需要有大量的实践和理论支撑,脚踏实地最为重要。用心做好每一件事,结果会给你最大的惊喜!

资源下载

更多资源
Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册