在本文中,我们将给您介绍关于linux–Node.jsExpress静态资产的区分大小写的详细内容,并且为您解答express静态资源的相关问题,此外,我们还将为您提供关于23-Node.js学习笔记
在本文中,我们将给您介绍关于linux – Node.js Express静态资产的区分大小写的详细内容,并且为您解答express 静态资源的相关问题,此外,我们还将为您提供关于23-Node.js学习笔记-Express-请求处理-静态资源的处理、asp.net – 如何在IIS Express下启用区分大小写?、C# WinForm 登录界面的图片验证码(区分大小写+不区分大小写)、Express js静态相对父目录的知识。
本文目录一览:- linux – Node.js Express静态资产的区分大小写(express 静态资源)
- 23-Node.js学习笔记-Express-请求处理-静态资源的处理
- asp.net – 如何在IIS Express下启用区分大小写?
- C# WinForm 登录界面的图片验证码(区分大小写+不区分大小写)
- Express js静态相对父目录
linux – Node.js Express静态资产的区分大小写(express 静态资源)
如何设置express.static的路由是否区分大小写?例如Express是否应该通过提供名为Image.jpeg的本地文件来处理对image.jpeg的请求.
调用express.Router([options])时有一个caseSensitive选项(如http://expressjs.com/en/4x/api.html所定义)但是当调用express.static(root,[options])时,这不是一个选项(同一链接上的文档).
默认情况下,我得到的不同行为是将不区分大小写的卷(/ Mac OS X)的静态文件提供给区分大小写的卷(/ Linux).这导致我们的应用程序中出现不一致的错误 – 在Mac OS X下本地不匹配的情况会在本地运行但在部署到Linux服务器时会失败.
解决方法:
我还获得了一些简单替代解决方案的建议:
Set a policy that all your static files and paths should be in lowercase.
Enforce the policy on the files by adding a build step that checks them.
Enforce the policy on requests by adding some middleware that rejects requests to the static folder if any uppercase characters are found in the path.
总结
以上是小编为你收集整理的linux – Node.js Express静态资产的区分大小写全部内容。
如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。
原文地址:https://codeday.me/bug/20190702/1354631.html
23-Node.js学习笔记-Express-请求处理-静态资源的处理
静态资源的处理
通过Express内置的express.static可以方便地托管静态文件,例如img,CSS,JavaScript 文件等
app.use(express.static(''public''));
现在,public目录下面的文件就可以访问了
- http://localhost:3000/images/01.png
- http://localhost:3000/css/01.css
- ...
//引入express框架
const express = require(''express'');
const path = require(''path'')
//创建网站服务器
const app = express();
//拦截所有的请求
app.use(express.static(path.join(__dirname,''public'')))
//监听端口
app.listen(3000);
console.log(''网站服务器启动成功'');
总结
以上是小编为你收集整理的23-Node.js学习笔记-Express-请求处理-静态资源的处理全部内容。
如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。
原文地址:https://www.cnblogs.com/foreverLuckyStar/p/12089561.html
asp.net – 如何在IIS Express下启用区分大小写?
目标是在部署到IIS和S3(S3区分大小写)之前,能够在本地捕获关于静态文件的大小写不一致.
谢谢
解决方法
…但不是文件.
IIS不区分大小写是一个误称,Windows文件系统不区分大小写,而不是IIS.如果URL包含文件路径,则IIS会询问Windows文件是否存在且操作系统是否响应而不考虑字母大小写. Windows中的文件名无法“启用”区分大小写.
但对于非真实文件路径,IIS是100%区分大小写的. URL字符的大小写完整地传递给IIS管道.无论是否存在区分大小写,都取决于Web应用程序.但好的做法是说你不希望/ page1与/ PAGE1不同.
ASP.NET对查询字符串变量名称不区分大小写.再次,这不是IIS.应用程序(ASP.NET)不区分大小写.
概要
静态文件路径不区分大小写(由于Windows操作系统,而不是IIS):
http://example.com/subdirectory/FILe.aspx
但是,不参与文件路径的URL的部分区分大小写(除了’x’参数之外的所有文件都在file.aspx之后,因为.aspx是ASP.NET资源):
http://example.com/subdirectory/FILe.aspx/Extra/Tail?x="query parameter"
如果应用程序区分大小写,则通过重写,HttpModules等动态生成的URL也区分大小写.这通常不是最佳做法,因为这两个URL会引用两个单独的网页:
http://example.com/2012/01/23/blog-article http://example.com/2012/01/23/BLOG-ARTICLE
C# WinForm 登录界面的图片验证码(区分大小写+不区分大小写)
一、功能界面

图1 验证码(区分大小写)
二、创建一个产生验证码的类Class1
(1)生成随机验证码字符串,用的是Random随机函数
(2)创建验证码图片,将该字符串画在PictureBox控件中
Class1.cs:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Drawing;//图片 using System.Windows.Forms; namespace ValidCodeTest { public class Class1 { #region 验证码功能 /// <summary> /// 生成随机验证码字符串 /// </summary> public static string CreateRandomCode(int CodeLength) { int rand; char code; string randomCode = String.Empty;//随机验证码 //生成一定长度的随机验证码 //Random random = new Random();//生成随机数对象 for (int i = 0; i < CodeLength; i++) { //利用GUID生成6位随机数 byte[] buffer = Guid.NewGuid().ToByteArray();//生成字节数组 int seed = BitConverter.ToInt32(buffer, 0);//利用BitConvert方法把字节数组转换为整数 Random random = new Random(seed);//以生成的整数作为随机种子 rand = random.Next(); //rand = random.Next(); if (rand % 3 == 1) { code = (char)(''A'' + (char)(rand % 26)); } else if (rand % 3 == 2) { code = (char)(''a'' + (char)(rand % 26)); } else { code = (char)(''0'' + (char)(rand % 10)); } randomCode += code.ToString(); } return randomCode; } /// <summary> /// 创建验证码图片 /// </summary> public static void CreateImage(string strValidCode, PictureBox pbox) { try { int RandAngle = 45;//随机转动角度 int MapWidth = (int)(strValidCode.Length * 21); Bitmap map = new Bitmap(MapWidth, 28);//验证码图片—长和宽 //创建绘图对象Graphics Graphics graph = Graphics.FromImage(map); graph.Clear(Color.AliceBlue);//清除绘画面,填充背景色 graph.DrawRectangle(new Pen(Color.Black, 0), 0, 0, map.Width - 1, map.Height - 1);//画一个边框 graph.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;//模式 Random rand = new Random(); //背景噪点生成 Pen blackPen = new Pen(Color.LightGray, 0); for (int i = 0; i < 50; i++) { int x = rand.Next(0, map.Width); int y = rand.Next(0, map.Height); graph.DrawRectangle(blackPen, x, y, 1, 1); } //验证码旋转,防止机器识别 char[] chars = strValidCode.ToCharArray();//拆散字符串成单字符数组 //文字居中 StringFormat format = new StringFormat(StringFormatFlags.NoClip); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; //定义颜色 Color[] c = { Color.Black, Color.Red, Color.DarkBlue, Color.Green, Color.Orange, Color.Brown, Color.DarkCyan, Color.Purple }; //定义字体 string[] font = { "Verdana", "Microsoft Sans Serif", "Comic Sans MS", "Arial", "宋体" }; for (int i = 0; i < chars.Length; i++) { int cindex = rand.Next(7); int findex = rand.Next(5); Font f = new System.Drawing.Font(font[findex], 13, System.Drawing.FontStyle.Bold);//字体样式(参数2为字体大小) Brush b = new System.Drawing.SolidBrush(c[cindex]); Point dot = new Point(16, 16); float angle = rand.Next(-RandAngle, RandAngle);//转动的度数 graph.TranslateTransform(dot.X, dot.Y);//移动光标到指定位置 graph.RotateTransform(angle); graph.DrawString(chars[i].ToString(), f, b, 1, 1, format); graph.RotateTransform(-angle);//转回去 graph.TranslateTransform(2, -dot.Y);//移动光标到指定位置 } pbox.Image = map; } catch (ArgumentException) { MessageBox.Show("验证码图片创建错误"); } } #endregion } }
三、调用
(1)更新验证码
(2)验证(区分大小写)
(3)验证(不区分大小写)
Form1.cs:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using ValidCodeTest; namespace ValidCode { public partial class Form1 : Form { public Form1() { InitializeComponent(); } #region 验证码 private const int ValidCodeLength = 4;//验证码长度 private String strValidCode = "";//验证码 //调用自定义函数,更新验证码 private void UpdateValidCode() { strValidCode = Class1.CreateRandomCode(ValidCodeLength);//生成随机验证码 if (strValidCode == "") return; Class1.CreateImage(strValidCode, pbox1);//创建验证码图片 } #endregion private void pbox1_Click(object sender, EventArgs e) { UpdateValidCode();//点击更新验证码 } private void Form1_Load(object sender, EventArgs e) { UpdateValidCode();//加载更新验证码 } /// <summary> /// 验证(区分大小写) /// </summary> private void btn1_Click(object sender, EventArgs e) { string validcode = txtValidCode.Text.Trim(); char[] ch1 = validcode.ToCharArray(); char[] ch2 = strValidCode.ToCharArray(); int Count1 = 0;//字母个数 int Count2 = 0;//数字个数 if (String.IsNullOrEmpty(validcode) != true)//验证码不为空 { for (int i = 0; i < strValidCode.Length; i++) { if ((ch1[i] >= ''a'' && ch1[i] <= ''z'') || (ch1[i] >= ''A'' && ch1[i] <= ''Z''))//字母 { if (ch1[i] == ch2[i]) { Count1++; } } else//数字 { if (ch1[i] == ch2[i]) { Count2++; } } } int CountSum = Count1 + Count2; if (CountSum == strValidCode.Length) { MessageBox.Show("验证通过", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); UpdateValidCode(); txtValidCode.Text = ""; txtValidCode.Focus(); } else { MessageBox.Show("验证失败", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); UpdateValidCode();//更新验证码 txtValidCode.Text = ""; txtValidCode.Focus(); } } else//验证码为空 { MessageBox.Show("请输入验证码", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); UpdateValidCode();//更新验证码 txtValidCode.Text = ""; txtValidCode.Focus(); } } /// <summary> /// 验证(不区分大小写) /// </summary> private void btn2_Click(object sender, EventArgs e) { string validcode = txtValidCode.Text.Trim(); if (String.IsNullOrEmpty(validcode) != true)//验证码不为空 { if (validcode.ToLower() == strValidCode.ToLower()) { MessageBox.Show("验证通过", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); UpdateValidCode(); txtValidCode.Text = ""; txtValidCode.Focus(); } else { MessageBox.Show("验证失败", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); UpdateValidCode();//更新验证码 txtValidCode.Text = ""; txtValidCode.Focus(); } } else//验证码为空 { MessageBox.Show("请输入验证码", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); UpdateValidCode();//更新验证码 txtValidCode.Text = ""; txtValidCode.Focus(); } } } }
.exe测试文件下载: ValidCode_jb51.zip
参考文章:
https://www.jianshu.com/p/d89f22cf51bf
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
- C# winform主界面打开并关闭登录界面的方法
- C# WinForm制作登录界面的实现步骤
Express js静态相对父目录
我目前在通过expressJs提供静态文件方面遇到一些小问题。
我的目录结构如下:
- 上市
- 的CSS
- LIB
- src
- 意见
- 家
- index.html
- server.js
在我的index.html
文件中,我在所有资产前面都加了一个斜杠。
我的静态设置如下: app.use(express.static(path.resolve(__dirname + '../' +
'public')));
但是由于某种原因,我的静态文件没有得到提供。
我当时以为这是跨域调用之类的…我目前正在使用cloud9 IDE,这可能与它有某种关系吗?
我们今天的关于linux – Node.js Express静态资产的区分大小写和express 静态资源的分享就到这里,谢谢您的阅读,如果想了解更多关于23-Node.js学习笔记-Express-请求处理-静态资源的处理、asp.net – 如何在IIS Express下启用区分大小写?、C# WinForm 登录界面的图片验证码(区分大小写+不区分大小写)、Express js静态相对父目录的相关信息,可以在本站进行搜索。
本文标签: