ASP.NET Boilerplate 学习

 

1、在http://www.aspnetboilerplate.com/Templates 网站下载ABP模版

2、解压后打开解决方案,解决方案目录:

3、在AbpTest.Web.Host项目的appsettings.json中配置数据库连接字符串

新建名为AbpTestDb的空白数据库,在NuGet包管理控制台 执行    Update-Database  命令,初始化数据库

4、运行应用程序将看到Swagger生成的API接口页面

AspNet Core2 浏览器缓存使用

 

Core2中使用Microsoft.AspNetCore.Mvc下的ResponseCacheAttribute特性来控制Http Get请求的缓存

原理是设置http请求 响应头的Cache-control来告诉浏览器如何进行客户端缓存

1、在Startup的ConfigureServices方法里面设置一个CacheProfiles,Duration属性定义浏览器缓存的秒数,CacheProfiles一个通用的缓存配置项

  1. services.AddMvc(option =>
  2. {
  3. /*客户端缓存*/
  4. option.CacheProfiles.Add("default", new Microsoft.AspNetCore.Mvc.CacheProfile
  5. {
  6. Duration = 600 /*10分钟*/
  7. });
  8. });

2、在需要缓存的Action上面添加ResponseCacheAttribute特性,CacheProfileName 的值使用服务配置的名称,该Action将使用配置项进行缓存

  1. [ResponseCache(CacheProfileName = "default")]

也可以在Action 上赋予 Duration 值,指定浏览器缓存的时间

查看ResponseCacheAttribute中的代码

  1. public unsafe IFilterMetadata CreateInstance(IServiceProvider serviceProvider)
  2. {
  3. //IL_0000: Unknown result type (might be due to invalid IL)
  4. //IL_0008: Unknown result type (might be due to invalid IL)
  5. //IL_000e: Unknown result type (might be due to invalid IL)
  6. //IL_0025: Unknown result type (might be due to invalid IL)
  7. //IL_0032: Expected Ref, but got Unknown
  8. //IL_0046: Unknown result type (might be due to invalid IL)
  9. if (serviceProvider == (IServiceProvider)0)
  10. {
  11. throw new ArgumentNullException("serviceProvider");
  12. }
  13. IOptions<MvcOptions> requiredService = serviceProvider.GetRequiredService<IOptions<MvcOptions>>();
  14. CacheProfile cacheProfile = null;
  15. if (this.CacheProfileName != null)
  16. {
  17. ((IDictionary)(?)requiredService.Value.CacheProfiles).TryGetValue((!0)this.CacheProfileName, ref *(!1*)(&cacheProfile));
  18. if (cacheProfile == null)
  19. {
  20. throw new InvalidOperationException(Resources.FormatCacheProfileNotFound(this.CacheProfileName));
  21. }
  22. }
  23. this._duration = (this._duration ?? ((cacheProfile != null) ? cacheProfile.Duration : null));
  24. this._noStore = (this._noStore ?? ((cacheProfile != null) ? cacheProfile.NoStore : null));
  25. this._location = (this._location ?? ((cacheProfile != null) ? cacheProfile.Location : null));
  26. this.VaryByHeader = (this.VaryByHeader ?? ((cacheProfile != null) ? cacheProfile.VaryByHeader : null));
  27. this.VaryByQueryKeys = (this.VaryByQueryKeys ?? ((cacheProfile != null) ? cacheProfile.VaryByQueryKeys : null));
  28. return new ResponseCacheFilter(new CacheProfile
  29. {
  30. Duration = this._duration,
  31. Location = this._location,
  32. NoStore = this._noStore,
  33. VaryByHeader = this.VaryByHeader,
  34. VaryByQueryKeys = this.VaryByQueryKeys
  35. });
  36. }

可以得知Action上设置-----优先级高于--CacheProfiles里面的配置

缓存最终通过ResponseCacheFilter过滤器来实现,ResponseCacheFilter 的代码:

  1. using Microsoft.AspNetCore.Http;
  2. using Microsoft.AspNetCore.Mvc.Core;
  3. using Microsoft.AspNetCore.Mvc.Filters;
  4. using Microsoft.AspNetCore.ResponseCaching;
  5. using System;
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. using System.Globalization;
  9. using System.Linq;
  10.  
  11. namespace Microsoft.AspNetCore.Mvc.Internal
  12. {
  13. /// <summary>
  14. /// An <see cref="T:Microsoft.AspNetCore.Mvc.Filters.IActionFilter" /> which sets the appropriate headers related to response caching.
  15. /// </summary>
  16. public class ResponseCacheFilter : IResponseCacheFilter, IActionFilter, IFilterMetadata
  17. {
  18. private readonly CacheProfile _cacheProfile;
  19.  
  20. private int? _cacheDuration;
  21.  
  22. private ResponseCacheLocation? _cacheLocation;
  23.  
  24. private bool? _cacheNoStore;
  25.  
  26. private string _cacheVaryByHeader;
  27.  
  28. private string[] _cacheVaryByQueryKeys;
  29.  
  30. /// <summary>
  31. /// Gets or sets the duration in seconds for which the response is cached.
  32. /// This is a required parameter.
  33. /// This sets "max-age" in "Cache-control" header.
  34. /// </summary>
  35. public int Duration
  36. {
  37. get
  38. {
  39. return (this._cacheDuration ?? this._cacheProfile.Duration) ?? 0;
  40. }
  41. set
  42. {
  43. this._cacheDuration = value;
  44. }
  45. }
  46.  
  47. /// <summary>
  48. /// Gets or sets the location where the data from a particular URL must be cached.
  49. /// </summary>
  50. public ResponseCacheLocation Location
  51. {
  52. get
  53. {
  54. return (this._cacheLocation ?? this._cacheProfile.Location) ?? ResponseCacheLocation.Any;
  55. }
  56. set
  57. {
  58. this._cacheLocation = value;
  59. }
  60. }
  61.  
  62. /// <summary>
  63. /// Gets or sets the value which determines whether the data should be stored or not.
  64. /// When set to <see langword="true" />, it sets "Cache-control" header to "no-store".
  65. /// Ignores the "Location" parameter for values other than "None".
  66. /// Ignores the "duration" parameter.
  67. /// </summary>
  68. public bool NoStore
  69. {
  70. get
  71. {
  72. return (this._cacheNoStore ?? this._cacheProfile.NoStore) ?? false;
  73. }
  74. set
  75. {
  76. this._cacheNoStore = value;
  77. }
  78. }
  79.  
  80. /// <summary>
  81. /// Gets or sets the value for the Vary response header.
  82. /// </summary>
  83. public string VaryByHeader
  84. {
  85. get
  86. {
  87. return this._cacheVaryByHeader ?? this._cacheProfile.VaryByHeader;
  88. }
  89. set
  90. {
  91. this._cacheVaryByHeader = value;
  92. }
  93. }
  94.  
  95. /// <summary>
  96. /// Gets or sets the query keys to vary by.
  97. /// </summary>
  98. /// <remarks>
  99. /// <see cref="P:Microsoft.AspNetCore.Mvc.Internal.ResponseCacheFilter.VaryByQueryKeys" /> requires the response cache middleware.
  100. /// </remarks>
  101. public string[] VaryByQueryKeys
  102. {
  103. get
  104. {
  105. return this._cacheVaryByQueryKeys ?? this._cacheProfile.VaryByQueryKeys;
  106. }
  107. set
  108. {
  109. this._cacheVaryByQueryKeys = value;
  110. }
  111. }
  112.  
  113. /// <summary>
  114. /// Creates a new instance of <see cref="T:Microsoft.AspNetCore.Mvc.Internal.ResponseCacheFilter" />
  115. /// </summary>
  116. /// <param name="cacheProfile">The profile which contains the settings for
  117. /// <see cref="T:Microsoft.AspNetCore.Mvc.Internal.ResponseCacheFilter" />.</param>
  118. public ResponseCacheFilter(CacheProfile cacheProfile)
  119. {
  120. this._cacheProfile = cacheProfile;
  121. }
  122.  
  123. /// <inheritdoc />
  124. public void OnActionExecuting(ActionExecutingContext context)
  125. {
  126. //IL_0008: Unknown result type (might be due to invalid IL)
  127. //IL_0051: Unknown result type (might be due to invalid IL)
  128. //IL_00d4: Unknown result type (might be due to invalid IL)
  129. //IL_0185: Unknown result type (might be due to invalid IL)
  130. if (context == null)
  131. {
  132. throw new ArgumentNullException("context");
  133. }
  134. if (!this.IsOverridden(context))
  135. {
  136. if (!this.NoStore && !this._cacheProfile.Duration.get_HasValue() && !this._cacheDuration.get_HasValue())
  137. {
  138. throw new InvalidOperationException(Resources.FormatResponseCache_SpecifyDuration("NoStore", "Duration"));
  139. }
  140. IHeaderDictionary headers = context.HttpContext.Response.Headers;
  141. ((IDictionary)(?)headers).Remove((!0)"Vary");
  142. ((IDictionary)(?)headers).Remove((!0)"Cache-Control");
  143. ((IDictionary)(?)headers).Remove((!0)"Pragma");
  144. if (!string.IsNullOrEmpty(this.VaryByHeader))
  145. {
  146. headers["Vary"] = this.VaryByHeader;
  147. }
  148. if (this.VaryByQueryKeys != null)
  149. {
  150. IResponseCachingFeature responseCachingFeature = context.HttpContext.Features.Get<IResponseCachingFeature>();
  151. if (responseCachingFeature == null)
  152. {
  153. throw new InvalidOperationException(Resources.FormatVaryByQueryKeys_Requires_ResponseCachingMiddleware("VaryByQueryKeys"));
  154. }
  155. responseCachingFeature.VaryByQueryKeys = this.VaryByQueryKeys;
  156. }
  157. if (this.NoStore)
  158. {
  159. headers["Cache-Control"] = "no-store";
  160. if (this.Location == ResponseCacheLocation.None)
  161. {
  162. headers.AppendCommaSeparatedValues("Cache-Control", "no-cache");
  163. headers["Pragma"] = "no-cache";
  164. }
  165. }
  166. else
  167. {
  168. string text = null;
  169. switch (this.Location)
  170. {
  171. case ResponseCacheLocation.Any:
  172. text = "public";
  173. break;
  174. case ResponseCacheLocation.Client:
  175. text = "private";
  176. break;
  177. case ResponseCacheLocation.None:
  178. text = "no-cache";
  179. headers["Pragma"] = "no-cache";
  180. break;
  181. }
  182. text = string.Format((IFormatProvider)CultureInfo.get_InvariantCulture(), "{0}{1}max-age={2}", (object)text, (object)((text != null) ? "," : null), (object)this.Duration);
  183. if (text != null)
  184. {
  185. headers["Cache-Control"] = text;
  186. }
  187. }
  188. }
  189. }
  190.  
  191. /// <inheritdoc />
  192. public void OnActionExecuted(ActionExecutedContext context)
  193. {
  194. }
  195.  
  196. internal bool IsOverridden(ActionExecutingContext context)
  197. {
  198. //IL_0008: Unknown result type (might be due to invalid IL)
  199. if (context == null)
  200. {
  201. throw new ArgumentNullException("context");
  202. }
  203. return Enumerable.Last<IResponseCacheFilter>(Enumerable.OfType<IResponseCacheFilter>((IEnumerable)context.Filters)) != this;
  204. }
  205. }
  206. }

c#基础,单线程,跨线程访问和线程带参数

 
  1. 1 using System;
  2. 2 using System.Collections.Generic;
  3. 3 using System.Threading;
  4. 4 using System.Windows.Forms;
  5. 5
  6. 6 namespace 线程和跨线程
  7. 7 {
  8. 8 public partial class Form1 : Form
  9. 9 {
  10. 10 public Form1()
  11. 11 {
  12. 12 InitializeComponent();
  13. 13 }
  14. 14 /// <summary>
  15. 15 /// 单线程直接假死了
  16. 16 /// </summary>
  17. 17 /// <param name="sender"></param>
  18. 18 /// <param name="e"></param>
  19. 19 private void btnAlone_Click(object sender, EventArgs e)
  20. 20 {
  21. 21 for (int i = 0; i < 100000; i++)
  22. 22 {
  23. 23 //通过[调试]-[窗口]-[输出]显示打印值
  24. 24 Console.WriteLine(i);
  25. 25 }
  26. 26 }
  27. 27
  28. 28
  29. 29 /// <summary>
  30. 30 /// 新线程运行,窗体不假死
  31. 31 /// </summary>
  32. 32 /// <param name="sender"></param>
  33. 33 /// <param name="e"></param>
  34. 34 private void btnNew_Click(object sender, EventArgs e)
  35. 35 {
  36. 36 Thread th = new Thread(ShowCalculator)
  37. 37 {
  38. 38 IsBackground = true
  39. 39 };
  40. 40 th.Start();
  41. 41
  42. 42 }
  43. 43 /// <summary>
  44. 44 /// 循环计算方法,供新线程使用
  45. 45 /// </summary>
  46. 46 private void ShowCalculator()
  47. 47 {
  48. 48 for (int i = 0; i < 100000; i++)
  49. 49 {//通过[调试]-[窗口]-[输出]显示打印值
  50. 50 Console.WriteLine(i);
  51. 51 }
  52. 52 }
  53. 53 /// <summary>
  54. 54 /// 带参数的
  55. 55 /// </summary>
  56. 56 /// <param name="sender"></param>
  57. 57 /// <param name="e"></param>
  58. 58 private void btnParameters_Click(object sender, EventArgs e)
  59. 59 {
  60. 60 List<int> list = new List<int>() { 1, 2, 3, 4, 5 };
  61. 61 ParameterizedThreadStart parThreadStart = new ParameterizedThreadStart(ShowParameters);
  62. 62 Thread th = new Thread(parThreadStart) { IsBackground = true };
  63. 63 th.Start(list);
  64. 64 }
  65. 65 private void ShowParameters(object obj)
  66. 66 {
  67. 67 //线程中的参数只能是Object
  68. 68 List<int> result = obj as List<int>;
  69. 69 foreach (var item in result)
  70. 70 {
  71. 71 MessageBox.Show(item.ToString());
  72. 72 }
  73. 73 }
  74. 74 /// <summary>
  75. 75 /// 跨线程访问
  76. 76 /// </summary>
  77. 77 /// <param name="sender"></param>
  78. 78 /// <param name="e"></param>
  79. 79 private void button1_Click(object sender, EventArgs e)
  80. 80 {
  81. 81 Thread th = new Thread(ShowMulti) { IsBackground = true };
  82. 82 th.Start();
  83. 83 }
  84. 84 /// <summary>
  85. 85 /// 解决跨线程访问报异常,不使用
  86. 86 /// </summary>
  87. 87 private void ShowMulti()
  88. 88 {
  89. 89 int first = 0;
  90. 90 for (int i = 0; i < 10; i++)
  91. 91 {
  92. 92 first = i;
  93. 93 }
  94. 94 //是否要对lbl控件进行跨线程
  95. 95 if (this.lblShow.InvokeRequired)
  96. 96 {
  97. 97 //对委托中的数据类型验证
  98. 98 this.lblShow.Invoke(new Action<Label, string>(ShowLableValue), this.lblShow, first.ToString());
  99. 99 }
  100. 100 else
  101. 101 {
  102. 102 this.lblShow.Text = first.ToString();
  103. 103 }
  104. 104 }
  105. 105 /// <summary>
  106. 106 /// 把值写到控件中
  107. 107 /// </summary>
  108. 108 /// <param name="lbl"></param>
  109. 109 /// <param name="value"></param>
  110. 110 private void ShowLableValue(Label lbl, string value)
  111. 111 {
  112. 112 lbl.Text = value;
  113. 113 }
  114. 114
  115. 115 private void Form1_Load(object sender, EventArgs e)
  116. 116 {
  117. 117 //关闭跨进程检查
  118. 118 //Label.CheckForIllegalCrossThreadCalls = false;
  119. 119 //改用委托方法实现
  120. 120 }
  121. 121 }
  122. 122 }

wpf 禁用启用webbroswer右键菜单

 
  1. //禁用脚本错误等类似的窗口信息
  2. this.webBrowser1.ScriptErrorsSuppressed = true;
  3. //禁用右键菜单
  4. this.webBrowser1.IsWebBrowserContextMenuEnabled = false;
  5. //禁用键盘快捷键
  6. this.webBrowser1.WebBrowserShortcutsEnabled = false;
  7. //打开IE打印机会话框
  8. this.webBrowser1.ShowPrintDialog();
  9. //打开IE的打印预览会话框
  10. this.webBrowser1.ShowPrintPreviewDialog();
  11. //打开IE的保存 会话框
  12. this.webBrowser1.ShowSaveAsDialog();

EF Core 2.0使用MsSql/MySql实现DB First和Code First

 

参考地址

Entity Framework官网

ASP.NET Core MVC 和 EF Core - 教程系列

环境

Visual Studio 2017

最新版本的.NET Core 2.0 SDK

最新版本的 Windows PowerShell

开始搭建

1、在 Visual Studio 2017 中创建新项目

  • “文件”>“新建”>“项目”
  • 从左侧菜单中选择“已安装”>“模板”>“Visual C#”>“.NET Core”。
  • 选择“ASP.NET Core Web 应用程序”。
  • 输入“EFGetStarted.AspNetCore.NewDb”作为名称,然后单击“确定”。
  • 在“新建 ASP.NET Core Web 应用程序”对话框中:
    • 确保在下拉列表中选择“.NET Core”和“ASP.NET Core 2.0”选项
    • 选择“Web 应用程序(模型视图控制器)”项目模板
    • 确保将“身份验证”设置为“无身份验证”
    • 单击“确定”

2、安装 Entity Framework Core

  • 工具”>“NuGet 包管理器”>“包管理器控制台”

1.1、安装数据库提供程序

MsSql

运行:Install-Package Microsoft.EntityFrameworkCore.SqlServer

MySql

运行:柚子:Install-Package Pomelo.EntityFrameworkCore.MySql
或者
官方:Install-Package MySql.Data.EntityFrameworkCore -Version 8.0.11

1.2、安装程序包管理器控制台
运行:Install-Package Microsoft.EntityFrameworkCore.Tools

1.3、安装设计包
运行:Install-Package Microsoft.EntityFrameworkCore.Design

数据据库提供程序设计包 (EF Core 2.0 不再需要)
MsSql

运行:Install-Package Microsoft.EntityFrameworkCore.SqlServer.Design
MySql

运行:Install-Package Pomelo.EntityFrameworkCore.MySql.Design

DB First——从现有数据库创建模型

MySql

运行:Scaffold-DbContext -Connection "Server=localhost;User Id=root;Password=123456;Database=vanfj" -Provider "Pomelo.EntityFrameworkCore.MySql" -OutputDir "Models"

MsSql

运行:Scaffold-DbContext -Connection "Server=localhost;User Id=root;Password=123456;Database=vanfj" -Provider "Microsoft.EntityFrameworkCore.SqlServer" -OutputDir "Models"

使用说明:将Connection中的连接字符串替换为自己的数据库连接,将OutputDir中的Models替换为自己要生成的文件目录名

Code First——从模型生成到数据库

1、创建模型

1.1、创建上下文

  1. public class SchoolContext : DbContext
  2. {
  3. public SchoolContext(DbContextOptions<SchoolContext> options) : base(options)
  4. {
  5. }
  6.  
  7. public DbSet<Course> Courses { get; set; }
  8. public DbSet<Enrollment> Enrollments { get; set; }
  9. public DbSet<Student> Students { get; set; }
  10.  
  11. protected override void OnModelCreating(ModelBuilder modelBuilder)
  12. {
  13. modelBuilder.Entity<Course>().ToTable("Course");
  14. modelBuilder.Entity<Enrollment>().ToTable("Enrollment");
  15. modelBuilder.Entity<Student>().ToTable("Student");
  16. }
  17. }
  18. public class Student
  19. {
  20. public int ID { get; set; }
  21. public string LastName { get; set; }
  22. public string FirstMidName { get; set; }
  23. public DateTime EnrollmentDate { get; set; }
  24.  
  25. public ICollection<Enrollment> Enrollments { get; set; }
  26. }
  27. public enum Grade
  28. {
  29. A, B, C, D, F
  30. }
  31.  
  32. public class Enrollment
  33. {
  34. public int EnrollmentID { get; set; }
  35. public int CourseID { get; set; }
  36. public int StudentID { get; set; }
  37. public Grade? Grade { get; set; }
  38.  
  39. public Course Course { get; set; }
  40. public Student Student { get; set; }
  41. }
  42. {
  43. A, B, C, D, F
  44. }
  45.  
  46. public class Enrollment
  47. {
  48. public int EnrollmentID { get; set; }
  49. public int CourseID { get; set; }
  50. public int StudentID { get; set; }
  51. public Grade? Grade { get; set; }
  52.  
  53. public Course Course { get; set; }
  54. public Student Student { get; set; }
  55. }
  56. public class Course
  57. {
  58. [DatabaseGenerated(DatabaseGeneratedOption.None)]
  59. public int CourseID { get; set; }
  60. public string Title { get; set; }
  61. public int Credits { get; set; }
  62.  
  63. public ICollection<Enrollment> Enrollments { get; set; }
  64. }

1.2、Startup文件注入上下文

EF Core在版本 2.0 中,引入了一种在依赖关系注入中注册自定义 DbContext 类型的新方法,即以透明形式引入可重用 DbContext 实例的池。 
要使用 DbContext 池,请在服务注册期间使用 AddDbContextPool 而不是 AddDbContext

  1. public void ConfigureServices(IServiceCollection services)
  2. {
  3. services.AddDbContextPool<SchoolContext>(options =>
  4. options.UseMySql(Configuration.GetConnectionString("DefaultConnection")));
  5.  
  6. services.AddMvc().AddJsonOptions(options =>
  7. options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);
  8. }

1.3、appsettings.json文件添加连接字符串

  1. {
  2. "ConnectionStrings": {
  3. "DefaultConnection": "Server=localhost;User Id=root;Password=123456;Database=vanfj"
  4. },
  5. "Logging": {
  6. "IncludeScopes": false,
  7. "LogLevel": {
  8. "Default": "Warning"
  9. }
  10. }
  11. }

2、执行NuGet命令,创建数据库

2.1、为迁移搭建基架

运行:Add-Migration InitialCreate

2.2、将新迁移应用到数据库

运行:Update-Database

EF Core 2.0 NuGet命令

Get-Help about_EntityFrameworkCore 获取EF Core命令帮助

添加一个迁移数据库 迁移的名称 目录(及其子命名空间)路径是相对于项目目录。 默认值为"Migrations"。
Add-Migration -Name <String> -OutputDir <String>
Add-Migration InitialCreate 第一次执行初始化用这个

删除上次的迁移数据库 不检查以查看迁移是否已应用到数据库。
Remove-Migration -Force

目标迁移。 如果为"0",将恢复所有迁移。 默认到最后一个迁移。
Update-Database 
Update-Database LastGoodMigration 还原迁移

删除数据库 显示的数据库会被丢弃,但没有删除它
Drop-Database -WhatIf

Get-DbContext 获取有关 DbContext 类型的信息

从数据库更新DbContext和实体的类型
Scaffold-DbContext 
-Connection <String> 数据库的连接字符串。
-Provider <String> 要使用的提供程序。 (例如 Microsoft.EntityFrameworkCore.SqlServer)
-OutputDir <String > 要将文件放入的目录。 路径是相对于项目目录。
--Context <String > 若要生成的 dbcontext 名称。
-Schemas <String[]> 要生成实体类型的表架构。
-Tables <String[]> 要生成实体类型的表。
-DataAnnotations 使用属性来配置该模型 (如果可能)。 如果省略,则使用仅 fluent API。
-UseDatabaseNames 使用直接从数据库表和列名称。
-Force 覆盖现有文件。

从迁移中生成的 SQL 脚本
Script-Migration
-From <String> 开始迁移。 默认值为 0 (初始数据库)
-To <String> 结束的迁移。 默认到最后一个迁移
-Idempotent 生成可以在任何迁移的数据库使用的脚本
-Output <String> 要将结果写入的文件

ASP.NET Core部署到Windows IIS

 

网上已经有许多ASP.NET Core关于Widows IIS部署的文章,在部署到服务器时遇到了一些问题,在这里我就不再对原理进行阐释(复制)了,只写下一些关键环节,想看原理的同学请参考官网,此文章作为留用。

步骤:

1、ASP.NET Core程序内配置

2、Windows Server配置

 一、ASP.NET Core应用程序配置

web.config 配置官方教程

重点修改 processPath 和 arguments 两个参数

processPath 修改为 dotnet

arguments 修改为 当前项目名称的dll

配置示例:

Startup 启用 IISIntegration 组件

FTP发布到IIS

在这里我使用的是VS FTP直接发布到IIS,也可以使用文件系统先发布到本地,两者任选一种都可以

二、Windows Server配置

安装环境

1、 Microsoft Visual C ++ 2015 Redistributable

2、.NET Core Hosting Bundle

目前这里这里链接的版本是DotNetCore.2.0.7-WindowsHosting,也可以在.NET所有下载自行选择对应的版本

提示:版本很重要,版本很重要,版本很重要

IIS配置

应用程序池设置为无托管代码

最后来测试是否成功

QRCode.js:使用 JavaScript 生成二维码

 

什么是 QRCode.js?

QRCode.js 是一个用于生成二维码的 JavaScript 库。主要是通过获取 DOM 的标签,再通过 HTML5 Canvas 绘制而成,不依赖任何库。

基本用法

载入 JavaScript 文件

  1. <script type="text/javascript" src="http://static.runoob.com/assets/qrcode/qrcode.min.js"></script>

DOM结构

  1. <div id="qrcode"></div>

JavaScropt调用

  1. //简单形式
  2. new QRCode(document.getElementById("qrcode"), "http://www.runoob.com"); // 设置要生成二维码的链接
  3.  
  4. // 设置参数方式
  5. var qrcode = new QRCode("test", {
  6. text: "http://www.runoob.com",
  7. width: 128,
  8. height: 128,
  9. colorDark : "#000000",
  10. colorLight : "#ffffff",
  11. correctLevel : QRCode.CorrectLevel.H
  12. });
  13.  
  14. // 使用 API
  15. qrcode.clear();
  16. qrcode.makeCode('new content');

参数说明

  1. new QRCode(element, option)
名称 默认值 说明
element - 显示二维码的元素或该元素的 ID
option   参数配置

option 参数说明

名称 默认值 说明
width 256 图像宽度
height 256 图像高度
colorDark "#000000" 前景色
colorLight "#ffffff" 背景色
correctLevel QRCode.CorrectLevel.L 容错级别,可设置为:

QRCode.CorrectLevel.L

QRCode.CorrectLevel.M

QRCode.CorrectLevel.Q

QRCode.CorrectLevel.H

API 接口

名称 说明
makeCode(text) 设置二维码内容
clear() 清除二维码。(仅在不支持 Canvas 的浏览器下有效)

浏览器支持

支持该库的浏览器有:IE6~10, Chrome, Firefox, Safari, Opera, Mobile Safari, Android, Windows Mobile, 等。

实例代码

HTML 代码

  1. <input id="text" type="text" value="http://www.runoob.com" /><br />
  2. <div id="qrcode"></div>

CSS 代码

  1. #qrcode {
  2. width:160px;
  3. height:160px;
  4. margin-top:15px;
  5. }

JavaScript 代码

  1. var qrcode = new QRCode("qrcode");
  2.  
  3. function makeCode () {
  4. var elText = document.getElementById("text");
  5.  
  6. if (!elText.value) {
  7. alert("Input a text");
  8. elText.focus();
  9. return;
  10. }
  11.  
  12. qrcode.makeCode(elText.value);
  13. }
  14.  
  15. makeCode();
  16.  
  17. $("#text").
  18. on("blur", function () {
  19. makeCode();
  20. }).
  21. on("keydown", function (e) {
  22. if (e.keyCode == 13) {
  23. makeCode();
  24. }
  25. });

HTML完整代码

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ko" lang="ko">
  3. <head>
  4. <title>Javascript 二维码生成库:QRCode</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  6. <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no" />
  7. <script type="text/javascript" src="http://cdn.bootcss.com/jquery/2.1.1/jquery.min.js"></script>
  8. <script type="text/javascript" src="http://static.runoob.com/assets/qrcode/qrcode.min.js"></script>
  9. </head>
  10. <body>
  11. <input id="text" type="text" value="http://www.runoob.com" style="width:80%" /><br />
  12. <div id="qrcode" style="width:100px; height:100px; margin-top:15px;"></div>
  13.  
  14. <script type="text/javascript">
  15. var qrcode = new QRCode(document.getElementById("qrcode"), {
  16. width : 100,
  17. height : 100
  18. });
  19.  
  20. function makeCode () {
  21. var elText = document.getElementById("text");
  22.  
  23. if (!elText.value) {
  24. alert("Input a text");
  25. elText.focus();
  26. return;
  27. }
  28.  
  29. qrcode.makeCode(elText.value);
  30. }
  31.  
  32. makeCode();
  33.  
  34. $("#text").
  35. on("blur", function () {
  36. makeCode();
  37. }).
  38. on("keydown", function (e) {
  39. if (e.keyCode == 13) {
  40. makeCode();
  41. }
  42. });
  43. </script>
  44. </body>
  45. </html>

ASP.NET Boilerplate 学习 AspNet Core2 浏览器缓存使用 c#基础,单线程,跨线程访问和线程带参数 wpf 禁用启用webbroswer右键菜单 EF Core 2.0使用MsSql/MySql实现DB First和Code First ASP.NET Core部署到Windows IIS QRCode.js:使用 JavaScript 生成的更多相关文章

  1. EF Core 2.0使用MsSql/Mysql实现DB First和Code First

    参考地址 EF官网 ASP.NET Core MVC 和 EF Core - 教程系列 环境 Visual Studio 2017 最新版本的.NET Core 2.0 SDK 最新版本的 Windo ...

  2. AspNet Core2 浏览器缓存使用

    Core2中使用Microsoft.AspNetCore.Mvc下的ResponseCacheAttribute特性来控制Http Get请求的缓存 原理是设置http请求 响应头的Cache-con ...

  3. [争什么! 掺在一起做撒尿牛丸啊! 笨蛋]ASP.NET Core 2.0 + EF6 + Linux +MySql混搭

    好消息!特好消息!同时使用ASP.NET Core 2.0和.NET Framework类库还能运行在linux上的方法来啦! 是的,你没有看错!ASP.NET Core 2.0,.NET Frame ...

  4. 【Asp.Net Core】ASP.NET Core 2.0 + EF6 + Linux +MySql混搭

    好消息!特好消息!同时使用ASP.NET Core 2.0和.NET Framework类库还能运行在linux上的方法来啦! 是的,你没有看错!ASP.NET Core 2.0,.NET Frame ...

  5. JavaWeb学习篇之----浏览器缓存问题详解

    摘要 1.Etag和Expires中Client 端Http Request Header及Server端Http Reponse Header工作原理. 2.静态下Apache.Lighttpd和N ...

  6. ASP.NET Boilerplate 学习

    1.在http://www.aspnetboilerplate.com/Templates 网站下载ABP模版 2.解压后打开解决方案,解决方案目录: 3.在AbpTest.Web.Host项目的ap ...

  7. ASP.NET Core部署到Windows IIS

    网上已经有许多ASP.NET Core关于Widows IIS部署的文章,在部署到服务器时遇到了一些问题,在这里我就不再对原理进行阐释(复制)了,只写下一些关键环节,想看原理的同学请参考官网,此文章作 ...

  8. Ubuntu & Docker & Consul & Fabio & ASP.NET Core 2.0 微服务跨平台实践

    相关博文: Ubuntu 简单安装 Docker Mac OS.Ubuntu 安装及使用 Consul Consul 服务注册与服务发现 Fabio 安装和简单使用 阅读目录: Docker 运行 C ...

  9. Docker & Consul & Fabio & ASP.NET Core 2.0 微服务跨平台实践

    相关博文: Ubuntu 简单安装 Docker Mac OS.Ubuntu 安装及使用 Consul Consul 服务注册与服务发现 Fabio 安装和简单使用 阅读目录: Docker 运行 C ...

随机推荐

  1. CAD插入背景图片(网页版)

    把图片作为背景图片可见但是不能编辑操作. 主要用到函数说明: _DMxDrawX::DrawImageToBackground 绘光栅图到背景.详细说明如下: 参数 说明 BSTR sFileName ...

  2. web.xml的简单解释以及Hello1中web.xml的简单分析

    一.web.xml的加载过程 ①当我们启动一个WEB项目容器时,容器包括(JBoss,Tomcat等).首先会去读取web.xml配置文件里的配置,当这一步骤没有出错并且完成之后,项目才能正常的被启动 ...

  3. JavaSE-21 字符编码简介

    ASCII ASCII(American Standard Code for Information Interchange,美国信息交换标准代码)是基于拉丁字母的一套电脑编码系统,主要用于显示现代英 ...

  4. li标签和checkbox绑定

    参考原文:https://www.cnblogs.com/youxin/p/3885496.html 我们经常需要li或span包含一个checkbox,不管点击checkbox或li都会触发相应的事 ...

  5. iOS中声音采集与播放的实现(使用AudioQueue)

    都说iOS最恶心的部分是流媒体,其中恶心的恶心之处更在即时语音. 所以我们先不谈即时语音,研究一下,iOS中声音采集与播放的实现. 要在iOS设备上实现录音和播放功能,苹果提供了简单的做法,那就是利用 ...

  6. 如何优雅的使用vue+Dcloud(Hbuild)开发混合app

    如何优雅的使用vue+Dcloud(Hbuild)开发混合app 最近在做混合app,前端框架用的是vue,打包app使用的是Dcloud,不过在开发过程中有一点不爽的是,如果想使用Dcloud提供的 ...

  7. MySQL数据库初识

    认识数据库 1 什么是数据(Data) 描述事物的符号记录称为数据,描述事物的符号既可以是数字,也可以是文字.图片,图像.声音.语言等,数据由多种表现形式,它们都可以经过数字化后存入计算机 在计算机中 ...

  8. TensorFlow - 相关 API

    来自:https://cloud.tencent.com/developer/labs/lab/10324 TensorFlow - 相关 API TensorFlow 相关函数理解 任务时间:时间未 ...

  9. 【分治】输出前k大的数

    描述 给定一个数组,统计前k大的数并且把这k个数从大到小输出. 输入第一行包含一个整数n,表示数组的大小.n < 100000.第二行包含n个整数,表示数组的元素,整数之间以一个空格分开.每个整 ...

  10. Unity 3D 使用Relief Terrain Pack(RTP) 问题

    Unity3D 5.2 RTP 3.2d -------------------------------------------------------------------- 使用RTP编译sha ...