原文:NET Framework项目移植到NET Core上遇到的一系列坑

版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。


目录

1.获取请求的参数

2.获取完整的请求路径

3.获取域名

4.编码

5.文件上传的保存方法

6.获取物理路径

7.返回Json属性大小写问题

8.webconfig的配置移植到appsettings.json

9.设置区域块MVC的路由器和访问区域块的视图

10.NetCore访问静态资源文件

11.MVC调用子页视图

12.过滤器

13.使用session和解决sessionID一直变化的问题

14.MD5加密

15.Path.Combine()

16.DateTime


1.获取请求的参数

NET Framework版本:

    1. Request["xxx"];
      1. Request.Files[0];
    1.  

    NET Core版本:

      1. Request.Form["xxx"];
        1. Request.Form.Files[0];
      1.  

      2.获取完整的请求路径

      NET Framework版本:

      1. Request.RequestUri.ToString();

      NET Core版本:

        1. //先添加引用
          1. using Microsoft.AspNetCore.Http.Extensions;
            1. //再调用
              1. Request.GetDisplayUrl();
            1.  

            3.获取域名

            NET Framework版本:

            1. HttpContext.Current.Request.Url.Authority

            NET Core版本:

            1. HttpContext.Request.Host.Value

            4.编码

            NET Framework版本:

              1. System.Web.HttpContext.Current.Server.UrlEncode("<li class=\"test\"></li>")
                1. "%3cli+class%3d%22test%22%3e%3c%2fli%3e"
                  1. System.Web.HttpContext.Current.Server.UrlDecode("%3cli+class%3d%22test%22%3e%3c%2fli%3e")
                    1. "<li class=\"test\"></li>"
                  1.  

                  NET Core版本:

                    1. //两种方法,建议用System.Web.HttpUtility
                      1. System.Web.HttpUtility.UrlEncode("<li class=\"test\"></li>");
                        1. "%3cli+class%3d%22test%22%3e%3c%2fli%3e"
                          1. System.Web.HttpUtility.UrlDecode("%3cli+class%3d%22test%22%3e%3c%2fli%3e");
                            1. "<li class=\"test\"></li>"
                                1. System.Net.WebUtility.UrlEncode("<li class=\"test\"></li>")
                                  1. "%3Cli+class%3D%22test%22%3E%3C%2Fli%3E"
                                    1. System.Net.WebUtility.UrlDecode("%3Cli+class%3D%22test%22%3E%3C%2Fli%3E")
                                      1. "<li class=\"test\"></li>"
                                        1. System.Net.WebUtility.UrlDecode("%3cli+class%3d%22test%22%3e%3c%2fli%3e")
                                          1. "<li class=\"test\"></li>"
                                          1.  

                                          5.文件上传的保存方法

                                          NET Framework版本:

                                            1. var file = Request.Files[0];
                                              1. //blockFullPath指保存的物理路径
                                                1. file.SaveAs(blockFullPath);
                                              1.  

                                              NET Core版本:

                                                1. var file = Request.Form.Files[0];
                                                  1. //blockFullPath指保存的物理路径
                                                    1. using (FileStream fs = new FileStream(blockFullPath, FileMode.CreateNew))
                                                      1. {
                                                        1. file.CopyTo(fs);
                                                          1. fs.Flush();
                                                            1. }
                                                          1.  

                                                          6.获取物理路径

                                                          NET Framework版本:

                                                            1. //作为一个全局变量获取物理路径的方法
                                                              1. public string ffmpegPathc = System.Web.Hosting.HostingEnvironment.MapPath("~/Content/ffmpeg/ffmpeg.exe");
                                                                1. //获取在控制器的构造函数里直接调用Server.MapPath
                                                                  1. ffmpegPathc = Server.MapPath("~/Content/ffmpeg/ffmpeg.exe");
                                                                1.  

                                                                NET Core版本:

                                                                从ASP.NET Core RC2开始,可以通过注入 IHostingEnvironment 服务对象来取得Web根目录和内容根目录的物理路径。代码如下:

                                                                  1. [Area("Admin")]
                                                                    1. public class FileUploadController : Controller
                                                                      1. {
                                                                        1. private readonly IHostingEnvironment _hostingEnvironment;
                                                                            1. public string ffmpegPathc = "";//System.Web.Hosting.HostingEnvironment.MapPath("~/Content/ffmpeg/ffmpeg.exe");
                                                                                1. public FileUploadController(IHostingEnvironment hostingEnvironment)
                                                                                  1. {
                                                                                    1. _hostingEnvironment = hostingEnvironment;
                                                                                      1. ffmpegPathc = _hostingEnvironment.WebRootPath + "/Content/ffmpeg/ffmpeg.exe";
                                                                                        1. }
                                                                                          1. }
                                                                                        1.  

                                                                                        这样写每个控制器就都要写一个构造函数,很麻烦,所以可以把它抽离出来,写个公共类去调用。代码如下:

                                                                                        先自定义一个静态类:

                                                                                          1. using Microsoft.AspNetCore.Hosting;
                                                                                            1. using Microsoft.Extensions.DependencyInjection;
                                                                                              1. using System;
                                                                                                  1. namespace GDSMPlateForm
                                                                                                    1. {
                                                                                                      1. public static class HttpHelper
                                                                                                        1. {
                                                                                                          1. public static IServiceProvider ServiceProvider { get; set; }
                                                                                                              1. public static string GetServerPath(string path)
                                                                                                                1. {
                                                                                                                  1. return ServiceProvider.GetRequiredService<IHostingEnvironment>().WebRootPath + path;
                                                                                                                    1. }
                                                                                                                      1. }
                                                                                                                        1. }
                                                                                                                      1.  

                                                                                                                      然后 在startup类下的Configure 方法下:

                                                                                                                      1. HttpHelper.ServiceProvider = app.ApplicationServices;

                                                                                                                      startup下的ConfigureServices放下注册方法(这一步必不可少,但是这里可以不写,因为IHostingEnvironment 是微软默认已经帮你注册了,如果是自己的服务,那么必须注册)。

                                                                                                                      1. services.AddSingleton<IHostingEnvironment, HostingEnvironment>();

                                                                                                                      最后获取物理路径就可以这样直接调用了:

                                                                                                                      1. public string ffmpegPathc = HttpHelper.GetServerPath("/Content/ffmpeg/ffmpeg.exe");

                                                                                                                      7.返回Json属性大小写问题

                                                                                                                      NET Core返回Json属性默认都会自动转为小写,但项目之前Json属性有些是大写的,所以需要配置成不转化为小写的形式。

                                                                                                                      Startup.cs的ConfigureServices方法下添加一行代码:

                                                                                                                        1. //Startup需要添加引用
                                                                                                                          1. using Newtonsoft.Json.Serialization;
                                                                                                                            1. //返回Json属性默认大小写
                                                                                                                              1. services.AddMvc().AddJsonOptions(o => { o.SerializerSettings.ContractResolver = new DefaultContractResolver(); });
                                                                                                                            1.  

                                                                                                                            8.webconfig的配置移植到appsettings.json

                                                                                                                            NET Framework版本:

                                                                                                                            直接可以读取webconfig配置文件:

                                                                                                                            1. string format = System.Configuration.ConfigurationManager.AppSettings["format"].ToString();

                                                                                                                            NET Core版本:

                                                                                                                            NET Core不再支持web.config,取而代之的是appsettings.json,所以需要把一些配置移植过去。

                                                                                                                            例如web.config下的一些配置

                                                                                                                              1. <appSettings>
                                                                                                                                1. <add key="ismdb" value="" />
                                                                                                                                  1. <add key="webpath" value="" />
                                                                                                                                    1. <add key="format" value="jpg,jpeg,png,gif,bmp,tif,svg/mp3,wav/mp4,avi,mpg,wmv,mkv,rmvb,mov,flv/zip/.ppt,.pptx" />
                                                                                                                                      1. <add key="imagesize" value="5242880" />
                                                                                                                                        1. <!--1024 * 1024 * 5 -->
                                                                                                                                          1. <add key="musicsize" value="20971520" />
                                                                                                                                            1. <!--1024 * 1024 * 20 -->
                                                                                                                                              1. <add key="mediasize" value="20971520" />
                                                                                                                                                1. <!--1024 * 1024 * 20 -->
                                                                                                                                                  1. <add key="packagesize" value="0" />
                                                                                                                                                    1. <add key="pptsize" value="0" />
                                                                                                                                                      1. </appSettings>
                                                                                                                                                    1.  

                                                                                                                                                    移植到appsettings.json

                                                                                                                                                      1. {
                                                                                                                                                        1. "Logging": {
                                                                                                                                                          1. "IncludeScopes": false,
                                                                                                                                                            1. "LogLevel": {
                                                                                                                                                              1. "Default": "Warning"
                                                                                                                                                                1. }
                                                                                                                                                                  1. },
                                                                                                                                                                    1. "webpath": "",
                                                                                                                                                                      1. "format": "jpg,jpeg,png,gif,bmp,tif,svg/mp3,wav/mp4,avi,mpg,wmv,mkv,rmvb,mov,flv/zip/.ppt,.pptx",
                                                                                                                                                                        1. "imagesize": "5242880",
                                                                                                                                                                          1. "musicsize": "20971520",
                                                                                                                                                                            1. "mediasize": "20971520",
                                                                                                                                                                              1. "packagesize": "0",
                                                                                                                                                                                1. "pptsize": "0"
                                                                                                                                                                                  1. }
                                                                                                                                                                                1.  

                                                                                                                                                                                然后编写一个类去调用这个appsettings.json

                                                                                                                                                                                  1. using Microsoft.Extensions.Configuration;
                                                                                                                                                                                    1. using System.IO;
                                                                                                                                                                                        1. namespace GDSMPlateForm
                                                                                                                                                                                          1. {
                                                                                                                                                                                            1. public class RConfigureManage
                                                                                                                                                                                              1. {
                                                                                                                                                                                                1. public static string GetConfigure(string key)
                                                                                                                                                                                                  1. {
                                                                                                                                                                                                      1. //添加 json 文件路径
                                                                                                                                                                                                        1. var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json");
                                                                                                                                                                                                          1. //创建配置根对象
                                                                                                                                                                                                            1. var configurationRoot = builder.Build();
                                                                                                                                                                                                                1. //取配置根下的 name 部分
                                                                                                                                                                                                                  1. string secvalue = configurationRoot.GetSection(key).Value;
                                                                                                                                                                                                                    1. return secvalue;
                                                                                                                                                                                                                      1. }
                                                                                                                                                                                                                        1. }
                                                                                                                                                                                                                          1. }
                                                                                                                                                                                                                        1.  

                                                                                                                                                                                                                        调用的方式:

                                                                                                                                                                                                                        1. string format = RConfigureManage.GetConfigure("format");

                                                                                                                                                                                                                        9.设置区域块MVC的路由器和访问区域块的视图

                                                                                                                                                                                                                        NET Framework版本:

                                                                                                                                                                                                                        NET Framework新建一个区域会自带一个类设置路由器的,如图:

                                                                                                                                                                                                                          1. using System.Web.Mvc;
                                                                                                                                                                                                                              1. namespace GDSMPlateForm.Areas.Admin
                                                                                                                                                                                                                                1. {
                                                                                                                                                                                                                                  1. public class AdminAreaRegistration : AreaRegistration
                                                                                                                                                                                                                                    1. {
                                                                                                                                                                                                                                      1. public override string AreaName
                                                                                                                                                                                                                                        1. {
                                                                                                                                                                                                                                          1. get
                                                                                                                                                                                                                                            1. {
                                                                                                                                                                                                                                              1. return "Admin";
                                                                                                                                                                                                                                                1. }
                                                                                                                                                                                                                                                  1. }
                                                                                                                                                                                                                                                      1. public override void RegisterArea(AreaRegistrationContext context)
                                                                                                                                                                                                                                                        1. {
                                                                                                                                                                                                                                                          1. context.MapRoute(
                                                                                                                                                                                                                                                            1. "Admin_default",
                                                                                                                                                                                                                                                              1. "Admin/{controller}/{action}/{id}",
                                                                                                                                                                                                                                                                1. new { action = "Index", id = UrlParameter.Optional }
                                                                                                                                                                                                                                                                  1. );
                                                                                                                                                                                                                                                                    1. }
                                                                                                                                                                                                                                                                      1. }
                                                                                                                                                                                                                                                                        1. }
                                                                                                                                                                                                                                                                      1.  

                                                                                                                                                                                                                                                                      NET Core版本:

                                                                                                                                                                                                                                                                      NET Core新建一个区域不会自带一个类用于设置路由器,所以需要在Startup类的Configure方法里多加一条路由器设置

                                                                                                                                                                                                                                                                        1. app.UseMvc(routes =>
                                                                                                                                                                                                                                                                          1. {
                                                                                                                                                                                                                                                                            1. routes.MapRoute(
                                                                                                                                                                                                                                                                              1. name: "areas",
                                                                                                                                                                                                                                                                                1. template: "{area:exists}/{controller=Home}/{action=Index}/{id?}"
                                                                                                                                                                                                                                                                                  1. );
                                                                                                                                                                                                                                                                                    1. });
                                                                                                                                                                                                                                                                                  1.  

                                                                                                                                                                                                                                                                                  然后需要在每个控制器下添加一个标签,指定该控制器属于哪个区域的,如图:

                                                                                                                                                                                                                                                                                  不加的话访问不到区域的视图,报404错误。

                                                                                                                                                                                                                                                                                  10.NetCore访问静态资源文件

                                                                                                                                                                                                                                                                                  NET Framework版本:

                                                                                                                                                                                                                                                                                  NET Framework可以在webconfig下配置这些静态资源文件

                                                                                                                                                                                                                                                                                    1. <staticContent>
                                                                                                                                                                                                                                                                                      1. <mimeMap fileExtension="." mimeType="image/svg+xml" />
                                                                                                                                                                                                                                                                                        1. <mimeMap fileExtension=".properties" mimeType="application/octet-stream" />
                                                                                                                                                                                                                                                                                          1. </staticContent>
                                                                                                                                                                                                                                                                                        1.  

                                                                                                                                                                                                                                                                                        NET Core版本:

                                                                                                                                                                                                                                                                                        NET Core并没有webconfig,所以需要在Startup类的Configure方法里自己配置。

                                                                                                                                                                                                                                                                                        NET Core项目默认的资源文件存在wwwroot下,可以通过app.UseStaticFiles方法自己定义资源文件的路径还有类型。

                                                                                                                                                                                                                                                                                          1. var provider = new FileExtensionContentTypeProvider();
                                                                                                                                                                                                                                                                                            1. provider.Mappings[".properties"] = "application/octet-stream";
                                                                                                                                                                                                                                                                                              1. app.UseStaticFiles(new StaticFileOptions
                                                                                                                                                                                                                                                                                                1. {
                                                                                                                                                                                                                                                                                                  1. FileProvider = new PhysicalFileProvider(
                                                                                                                                                                                                                                                                                                    1. Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "Content")),
                                                                                                                                                                                                                                                                                                      1. RequestPath = "/Content",
                                                                                                                                                                                                                                                                                                        1. ContentTypeProvider = provider
                                                                                                                                                                                                                                                                                                          1. });
                                                                                                                                                                                                                                                                                                        1.  

                                                                                                                                                                                                                                                                                                        11.MVC调用子页视图

                                                                                                                                                                                                                                                                                                        NET Framework版本:

                                                                                                                                                                                                                                                                                                        1. @Html.Action("UserBackView", "UserManage")

                                                                                                                                                                                                                                                                                                        NET Core版本:

                                                                                                                                                                                                                                                                                                        NET Core不再支持Html.Action(),不过可以手动自己去实现它。

                                                                                                                                                                                                                                                                                                        自定义一个静态类 HtmlHelperViewExtensions,命名空间设置为  Microsoft.AspNetCore.Mvc.Rendering。网上找的一个类,复制过来就行了,如下:

                                                                                                                                                                                                                                                                                                          1. using Microsoft.AspNetCore.Html;
                                                                                                                                                                                                                                                                                                            1. using Microsoft.AspNetCore.Http;
                                                                                                                                                                                                                                                                                                              1. using Microsoft.AspNetCore.Mvc.Infrastructure;
                                                                                                                                                                                                                                                                                                                1. using Microsoft.AspNetCore.Routing;
                                                                                                                                                                                                                                                                                                                  1. using Microsoft.Extensions.DependencyInjection;
                                                                                                                                                                                                                                                                                                                    1. using System;
                                                                                                                                                                                                                                                                                                                      1. using System.IO;
                                                                                                                                                                                                                                                                                                                        1. using System.Threading.Tasks;
                                                                                                                                                                                                                                                                                                                            1. namespace Microsoft.AspNetCore.Mvc.Rendering
                                                                                                                                                                                                                                                                                                                              1. {
                                                                                                                                                                                                                                                                                                                                1. public static class HtmlHelperViewExtensions
                                                                                                                                                                                                                                                                                                                                  1. {
                                                                                                                                                                                                                                                                                                                                    1. public static IHtmlContent Action(this IHtmlHelper helper, string action, object parameters = null)
                                                                                                                                                                                                                                                                                                                                      1. {
                                                                                                                                                                                                                                                                                                                                        1. var controller = (string)helper.ViewContext.RouteData.Values["controller"];
                                                                                                                                                                                                                                                                                                                                            1. return Action(helper, action, controller, parameters);
                                                                                                                                                                                                                                                                                                                                              1. }
                                                                                                                                                                                                                                                                                                                                                  1. public static IHtmlContent Action(this IHtmlHelper helper, string action, string controller, object parameters = null)
                                                                                                                                                                                                                                                                                                                                                    1. {
                                                                                                                                                                                                                                                                                                                                                      1. var area = (string)helper.ViewContext.RouteData.Values["area"];
                                                                                                                                                                                                                                                                                                                                                          1. return Action(helper, action, controller, area, parameters);
                                                                                                                                                                                                                                                                                                                                                            1. }
                                                                                                                                                                                                                                                                                                                                                                1. public static IHtmlContent Action(this IHtmlHelper helper, string action, string controller, string area, object parameters = null)
                                                                                                                                                                                                                                                                                                                                                                  1. {
                                                                                                                                                                                                                                                                                                                                                                    1. if (action == null)
                                                                                                                                                                                                                                                                                                                                                                      1. throw new ArgumentNullException("action");
                                                                                                                                                                                                                                                                                                                                                                          1. if (controller == null)
                                                                                                                                                                                                                                                                                                                                                                            1. throw new ArgumentNullException("controller");
                                                                                                                                                                                                                                                                                                                                                                                  1. var task = RenderActionAsync(helper, action, controller, area, parameters);
                                                                                                                                                                                                                                                                                                                                                                                      1. return task.Result;
                                                                                                                                                                                                                                                                                                                                                                                        1. }
                                                                                                                                                                                                                                                                                                                                                                                            1. private static async Task<IHtmlContent> RenderActionAsync(this IHtmlHelper helper, string action, string controller, string area, object parameters = null)
                                                                                                                                                                                                                                                                                                                                                                                              1. {
                                                                                                                                                                                                                                                                                                                                                                                                1. // fetching required services for invocation
                                                                                                                                                                                                                                                                                                                                                                                                  1. var serviceProvider = helper.ViewContext.HttpContext.RequestServices;
                                                                                                                                                                                                                                                                                                                                                                                                    1. var actionContextAccessor = helper.ViewContext.HttpContext.RequestServices.GetRequiredService<IActionContextAccessor>();
                                                                                                                                                                                                                                                                                                                                                                                                      1. var httpContextAccessor = helper.ViewContext.HttpContext.RequestServices.GetRequiredService<IHttpContextAccessor>();
                                                                                                                                                                                                                                                                                                                                                                                                        1. var actionSelector = serviceProvider.GetRequiredService<IActionSelector>();
                                                                                                                                                                                                                                                                                                                                                                                                            1. // creating new action invocation context
                                                                                                                                                                                                                                                                                                                                                                                                              1. var routeData = new RouteData();
                                                                                                                                                                                                                                                                                                                                                                                                                1. foreach (var router in helper.ViewContext.RouteData.Routers)
                                                                                                                                                                                                                                                                                                                                                                                                                  1. {
                                                                                                                                                                                                                                                                                                                                                                                                                    1. routeData.PushState(router, null, null);
                                                                                                                                                                                                                                                                                                                                                                                                                      1. }
                                                                                                                                                                                                                                                                                                                                                                                                                        1. routeData.PushState(null, new RouteValueDictionary(new { controller = controller, action = action, area = area }), null);
                                                                                                                                                                                                                                                                                                                                                                                                                          1. routeData.PushState(null, new RouteValueDictionary(parameters ?? new { }), null);
                                                                                                                                                                                                                                                                                                                                                                                                                              1. //get the actiondescriptor
                                                                                                                                                                                                                                                                                                                                                                                                                                1. RouteContext routeContext = new RouteContext(helper.ViewContext.HttpContext) { RouteData = routeData };
                                                                                                                                                                                                                                                                                                                                                                                                                                  1. var candidates = actionSelector.SelectCandidates(routeContext);
                                                                                                                                                                                                                                                                                                                                                                                                                                    1. var actionDescriptor = actionSelector.SelectBestCandidate(routeContext, candidates);
                                                                                                                                                                                                                                                                                                                                                                                                                                        1. var originalActionContext = actionContextAccessor.ActionContext;
                                                                                                                                                                                                                                                                                                                                                                                                                                          1. var originalhttpContext = httpContextAccessor.HttpContext;
                                                                                                                                                                                                                                                                                                                                                                                                                                            1. try
                                                                                                                                                                                                                                                                                                                                                                                                                                              1. {
                                                                                                                                                                                                                                                                                                                                                                                                                                                1. var newHttpContext = serviceProvider.GetRequiredService<IHttpContextFactory>().Create(helper.ViewContext.HttpContext.Features);
                                                                                                                                                                                                                                                                                                                                                                                                                                                  1. if (newHttpContext.Items.ContainsKey(typeof(IUrlHelper)))
                                                                                                                                                                                                                                                                                                                                                                                                                                                    1. {
                                                                                                                                                                                                                                                                                                                                                                                                                                                      1. newHttpContext.Items.Remove(typeof(IUrlHelper));
                                                                                                                                                                                                                                                                                                                                                                                                                                                        1. }
                                                                                                                                                                                                                                                                                                                                                                                                                                                          1. newHttpContext.Response.Body = new MemoryStream();
                                                                                                                                                                                                                                                                                                                                                                                                                                                            1. var actionContext = new ActionContext(newHttpContext, routeData, actionDescriptor);
                                                                                                                                                                                                                                                                                                                                                                                                                                                              1. actionContextAccessor.ActionContext = actionContext;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                1. var invoker = serviceProvider.GetRequiredService<IActionInvokerFactory>().CreateInvoker(actionContext);
                                                                                                                                                                                                                                                                                                                                                                                                                                                                  1. await invoker.InvokeAsync();
                                                                                                                                                                                                                                                                                                                                                                                                                                                                    1. newHttpContext.Response.Body.Position = 0;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                      1. using (var reader = new StreamReader(newHttpContext.Response.Body))
                                                                                                                                                                                                                                                                                                                                                                                                                                                                        1. {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                          1. return new HtmlString(reader.ReadToEnd());
                                                                                                                                                                                                                                                                                                                                                                                                                                                                            1. }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                              1. }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                1. catch (Exception ex)
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  1. {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    1. return new HtmlString(ex.Message);
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      1. }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        1. finally
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          1. {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            1. actionContextAccessor.ActionContext = originalActionContext;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              1. httpContextAccessor.HttpContext = originalhttpContext;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                1. if (helper.ViewContext.HttpContext.Items.ContainsKey(typeof(IUrlHelper)))
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  1. {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    1. helper.ViewContext.HttpContext.Items.Remove(typeof(IUrlHelper));
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      1. }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        1. }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          1. }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            1. }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              1. }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            1.  

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            然后在Startup中的 ConfigureServices 方法添加:

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              1. services.AddSingleton<IHttpContextAccessor, HttpContextAccessor();
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                1. services.AddSingleton<IActionContextAccessor, ActionContextAccessor>();
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              1.  

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              这样就可以像NET Framework版本一样去调用子页面视图了:

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              1. @Html.Action("UserBackView", "UserManage")

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              12.过滤器

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              NET Framework版本

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              NET Framework版本上Global.asax中Application_Start方法可以做很多配置,过滤器也是其中一种。

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                1. protected void Application_Start()
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  1. {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    1. AreaRegistration.RegisterAllAreas();
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      1. FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);//全局过滤器集合
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        1. RouteConfig.RegisterRoutes(RouteTable.Routes);
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          1. BundleConfig.RegisterBundles(BundleTable.Bundles);
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            1. }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                1. public class FilterConfig
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  1. {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    1. public static void RegisterGlobalFilters(GlobalFilterCollection filters)
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      1. {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        1. filters.Add(new HandleErrorAttribute());
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          1. filters.Add(new LoginCheckFilterAttribute() { IsCheck = true });//自定义一个过滤器
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            1. }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              1. }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  1. //继承过滤器基类并重写方法
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    1. public class LoginCheckFilterAttribute : ActionFilterAttribute
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      1. {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        1. //表示是否检查
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          1. public bool IsCheck { get; set; }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            1. //Action方法执行之前执行此方法
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              1. public override void OnActionExecuting(ActionExecutingContext filterContext)
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                1. {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  1. base.OnActionExecuting(filterContext);
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    1. if (IsCheck)
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      1. {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        1. //添加自己的逻辑
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          1. }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            1. }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              1. }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            1.  

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            NET Core版本:

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            NET Core不在支持Global.asax,很多配置写在Startup里。过滤器的添加方法如下:

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              1. public void ConfigureServices(IServiceCollection services)
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                1. {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  1. services.AddMvc(options =>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    1. {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      1. options.Filters.Add(typeof(AuthorizationFilters));// 自定义一个类AuthorizationFilters,添加身份验证过滤器
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        1. });
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          1. }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              1. /// <summary>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                1. /// 身份认证类继承IAuthorizationFilter接口
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  1. /// </summary>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    1. public class AuthorizationFilters :IAuthorizationFilter
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      1. {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        1. /// <summary>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          1. /// 请求验证,当前验证部分不要抛出异常,ExceptionFilter不会处理
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            1. /// </summary>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              1. /// <param name="context">请求内容信息</param>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                1. public void OnAuthorization(AuthorizationFilterContext context)
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  1. {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    1. //写自己的逻辑
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      1. }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        1. }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      1.  

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      13.使用session和解决sessionID一直变化的问题

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      NET Core版本:

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      在Startup类里添加session配置

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        1. public void ConfigureServices(IServiceCollection services)
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          1. {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            1. services.AddDistributedMemoryCache();
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              1. services.AddSession(option =>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                1. { //设置session过期时间
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  1. option.IOTimeout = TimeSpan.FromHours(1);
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    1. option.IdleTimeout = TimeSpan.FromHours(1);
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      1. });
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        1. services.AddMvc();
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          1. }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              1. public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider svp)
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                1. {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  1. app.UseSession();//必须在app.UseMvc之前,否则报错
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    1. app.UseMvc(routes =>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      1. {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        1. routes.MapRoute(
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          1. name: "default",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            1. template: "{controller=Home}/{action=Index}/{id?}");
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              1. });
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                1. }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              1.  

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              配置完成后session就可以使用了,不过当Session保存有值,id才不会改变,没有值每次刷新都会变,可以给在使用session时可以给session随便赋个值以保证sessionid不会一直变化。

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                1. HttpContext.Session.Set("login", Encoding.UTF8.GetBytes("login"));
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  1. string sessionid = HttpContext.Session.Id;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                1.  

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                14.MD5加密

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                NET Framework版本:

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  1. //参数str类型是string
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    1. System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5");
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  1.  

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  NET Core版本:用以下这个方法替换了

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    1. /// <summary>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      1. /// 32位MD5加密
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        1. /// </summary>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          1. /// <param name="input"></param>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            1. /// <returns></returns>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              1. private static string Md5Hash(string input)
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                1. {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  1. MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    1. byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(input));
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      1. StringBuilder sBuilder = new StringBuilder();
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        1. for (int i = 0; i < data.Length; i++)
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          1. {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            1. sBuilder.Append(data[i].ToString("x2"));
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              1. }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                1. return sBuilder.ToString();
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  1. }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                1.  

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                15.Path.Combine()

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                该方法是路径拼接,在NET Framework版本和NET Core版本同样支持,不过用Path.Combine拼接出来的路径是这样的:xxxx\\xxxx,用的是“\\”,这种路径在Window系统上可以正常运行,但是在Linux上是无法定位到准确的路径的。Linux上的路径是这样的:xxxx/xxxx。所以当我们用Path.Combine这个方法时最好再配合一个替换方法:

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                1. Path.Combine(path1,path2).Replace("\\","/");

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                16.DateTime

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                donet core 2.1 DateTime.Now.ToString() 方法在不同平台返回的时间格式不一样,即使使用ToString("yyyy/MM/dd")希望转成'2019/04/18'这种格式,但在Centos7平台下它还是变成了‘2019-04-18’这样,可以考虑用Replace方法去替换。

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                NET Framework项目移植到NET Core上遇到的一系列坑的更多相关文章

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                1. NET Framework项目移植到NET Core上遇到的一系列坑(2)

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  目录 获取请求的参数 获取完整的请求路径 获取域名 编码 文件上传的保存方法 获取物理路径 返回Json属性大小写问题 webconfig的配置移植到appsettings.json 设置区域块MVC ...

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                2. NET Framework项目移植到NET Core上踩的坑(1)

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  本文章向大家介绍NET Framework项目移植到NET Core上遇到的一系列坑,主要包括NET Framework项目移植到NET Core上遇到的一系列坑使用实例.应用技巧.基本知识点总结和需 ...

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                3. 在Visual Studio中将现有.NET Framework项目迁移至.NET Core 1.1 Preview 1

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  1)下载安装包含 .NET Core 1.1 Preview 1 的 SDK:Windows x64 安装包(下载地址列表) 2)下载最新 VS 2015 NuGet 插件:https://dist. ...

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                4. 如何移植.NET Framework项目至.NET Core?

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  公司的项目一直采用.NET框架来开发Web项目.目前基础类库均为.NET Framework 4.6.2版本.Caching, Logging,DependencyInjection,Configur ...

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                5. 开源纯C#工控网关+组态软件(十)移植到.NET Core

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  一.   引子 写这个开源系列已经十来篇了.自从十年前注册博客园以来,关注了张善友.老赵.xiaotie.深蓝色右手等一众大牛,也围观了逗比的吉日嘎啦.精密顽石等形形色色的园友.然而整整十年一篇文章都 ...

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                6. 通俗易懂,什么是.NET?什么是.NET Framework?什么是.NET Core? .Net Web开发技术栈

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  通俗易懂,什么是.NET?什么是.NET Framework?什么是.NET Core?   什么是.NET?什么是.NET Framework?本文将从上往下,循序渐进的介绍一系列相关.NET的概念 ...

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                7. .NET项目迁移到.NET Core操作指南

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  为什么要从.NET迁移到.NET Core? .NET Core提供的特性 .NET Core性能提升 .NET如何迁移到.NET Core? 迁移工作量评估(API兼容性分析) 迁移方案制定 通过类 ...

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                8. (转)项目迁移_.NET项目迁移到.NET Core操作指南

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  原文地址:https://www.cnblogs.com/heyuquan/p/dotnet-migration-to-dotnetcore.html 这篇文章,汇集了大量优秀作者写的关于" ...

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                9. .Net Core上用于代替System.Drawing的类库

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  目前.Net Core上没有System.Drawing这个类库,想要在.Net Core上处理图片得另辟蹊径. 微软给出了将来取代System.Drawing的方案,偏向于使用一个单独的服务端进行各 ...

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                随机推荐

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                1. C# 子类与父类构造函数

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                2. 堡垒机WebSSH进阶之实时监控和强制下线

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  这个功能我可以不用,但你不能没有 前几篇文章实现了对物理机.虚拟机以及Kubernetes中Pod的WebSSH操作,可以方便的在web端对系统进行管理,同时也支持对所有操作进行全程录像,以方便后续的 ...

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                3. 在文件夹下所有文件中查找字符串(linux/windows)

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  在linux下可以用 grep "String" filename.txt#字符串 文件名grep -r "String" /home/#递归查找目录下所有文件 ...

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                4. java.lang.ClassNotFoundException: com.demo.search.extractAbstract.service.ExtractAbstractServiceHandler

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  在利用 Spring 对 thrift 进行集成时,出现错误: avax.servlet.ServletException: Servlet.init() for servlet search-nlp ...

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                5. [TimLinux] Python3.6 异常继承关系

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  Python3.6 异常继承结构 object └── BaseException ├── Exception │   ├── ArithmeticError │   │   ├── Floating ...

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                6. [TimLinux] JavaScript 中循环执行和定时执行

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  1. 两对函数 // 循环执行 // 在每个毫秒数之后,调用函数 var timeid = window.setInterval(函数名, 毫秒数); window.clearInterval(tim ...

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                7. [TimLinux] myblog 数据表格显示

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  1. 设计 2. 数据 创建数据库用户: CREATE USER IF NOT EXISTS 'user1'@'MyBlogPwd123'; GRANT ALL ON d1.* TO 'user1'@ ...

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                8. 赌十包辣条,你一定没见过这么通透的ThreadLocal讲解

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  1.看个热闹 鉴于普罗大众都喜欢看热闹,咱们先来看个热闹再开工吧! 场景一: 中午了, 张三.李四和王五一起去食堂大菜吃饭.食堂刚经营不久,还很简陋,负责打菜的只有一位老阿姨. 张三:我要一份鸡腿. ...

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                9. 基于RT-Thread的人体健康监测系统

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  随着生活质量的提高和生活节奏的加快,人们愈加需要关注自己的健康状况,本项目意在设计一种基于云平台+APP+设备端的身体参数测试系统,利用脉搏传感器.红外传感器.微弱信号检测电路等实现人体参数的采集,数 ...

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                10. SoC的软件开发流程,主要包含一些Linux下的操作命令

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  该笔记主要记录SoC的软件开发流程,主要包含一些Linux下的操作命令 1. 编写design file .c .h 2. 编写makefile    可执行文件名,交叉编译环境,compile fl ...