标签:http -o editor .com read 跳过 level oct str
选择Controllers文件夹,右键-添加-新建项,选择MVC控制器类,添加HomeController.cs。
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; namespace RazorMvc.Controllers { public class HomeController : Controller { // GET: Home public ActionResult Index() { return View(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace RazorMvc.Models { public class HomeModel { } }
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>@ViewData["Title"]</title> </head> <body> @RenderBody() @RenderSection("Scripts", false) </body> </html>
@{ Layout = "~/Views/_Layout.cshtml"; }
@using 项目命名空间
@using 项目命名空间.Models
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
public void ConfigureServices(IServiceCollection services) { services.AddMvc();//注册服务 } public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseSession(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }
Install-Package Microsoft.EntityFrameworkCore.SqlServer
Install-Package Microsoft.EntityFrameworkCore.Tools
Install-Package Microsoft.VisualStudio.Web.CodeGeneration.Design
Scaffold-DbContext"Server=.;Database=test;uid=test;pwd=test;"Microsoft.EntityFrameworkCore.SqlServer-OutputDirModels
可以通过将-Tables
参数添加到上述命令来指定要为哪些表生成实体。 例如-Tables Blog,Post
。
Models\BloggingContext.cs
OnConfiguring(...)
方法public void ConfigureServices(IServiceCollection services) { services.AddMvc(); var connection = @"Server=.;Database=test;uid=test;pwd=test;"; services.AddDbContext<testContext>(options => options.UseSqlServer(connection)); }
//根据自己需要修改配置文件,此处直接https://www.cnblogs.com/shouwu/p/6180652.html,
Microsoft.AspNetCore.Session; Microsoft.AspNetCore.DataProtection.Redis; Microsoft.Extensions.Caching.Redis.Core; Microsoft.AspNetCore.Http; //使用Session时有扩展方法
{ "Logging": { "LogLevel": { "Default": "Warning" } }, "AllowedHosts": "*", "WebConfig": { "Redis": { "Connection": "ip:6379,allowAdmin=true,password=Test", "InstanceName": "名称" }, "SessionTimeOut": "30" } }
public IConfiguration Configuration { get; } public Startup(IConfiguration configuration) { Configuration = configuration; }
ConfigureServices() 增加
#region 使用Redis保存Session var redisConn = Configuration["WebConfig:Redis:Connection"]; var redisInstanceName = Configuration["WebConfig:Redis:InstanceName"]; //Session 过期时长分钟 var sessionOutTime = Configuration.GetValue<int>("WebConfig:SessionTimeOut", 30); var redis = StackExchange.Redis.ConnectionMultiplexer.Connect(redisConn); services.AddDataProtection().PersistKeysToRedis(redis, "DataProtection-Test-Keys"); services.AddDistributedRedisCache(option => { //redis 连接字符串 option.Configuration = redisConn; //redis 实例名 option.InstanceName = redisInstanceName; }); #endregion //添加Session并设置过期时长 services.AddSession(options => { options.IdleTimeout = TimeSpan.FromMinutes(sessionOutTime); });
Configure() 在app.UseMvc之前增加
app.UseSession();
HttpContext.Session.SetString("UserName", userName); HttpContext.Session.GetString("UserName");
public IDistributedCache _RCache { get; set; } public MyToolController(IDistributedCache RCache) { _RCache = RCache; } _RCache.SetString("UserName", UserName); _RCache.GetString("UserName");
Install-Package YUICompressor.NET
JavaScriptCompressor jsCompressor = new JavaScriptCompressor { //使用utf-8 编码文件 Encoding = Encoding.UTF8 }; jsCompressor.Compress(str);
CssCompressor cssCompressor = new CssCompressor(); cssCompressor.Compress(str);
标签:http -o editor .com read 跳过 level oct str
原文地址:https://www.cnblogs.com/hqxc/p/9414410.html