主頁 > .NET開發 > NET Framework專案移植到NET Core上遇到的一系列坑(2)

NET Framework專案移植到NET Core上遇到的一系列坑(2)

2020-09-19 09:57:50 .NET開發

目錄

  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"];
2 Request.Files[0];

NET Core版本:

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

2.獲取完整的請求路徑

NET Framework版本:

1 Request.RequestUri.ToString(); 

NET Core版本:

1 //先添加參考
2  
3 using Microsoft.AspNetCore.Http.Extensions;
4  
5 //再呼叫
6 Request.GetDisplayUrl();

 

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>")
2 "%3cli+class%3d%22test%22%3e%3c%2fli%3e"
3 System.Web.HttpContext.Current.Server.UrlDecode("%3cli+class%3d%22test%22%3e%3c%2fli%3e")
4 "<li class=\"test\"></li>"

NET Core版本:

 1 //兩種方法,建議用System.Web.HttpUtility
 2 System.Web.HttpUtility.UrlEncode("<li class=\"test\"></li>");
 3 "%3cli+class%3d%22test%22%3e%3c%2fli%3e"
 4 System.Web.HttpUtility.UrlDecode("%3cli+class%3d%22test%22%3e%3c%2fli%3e");
 5 "<li class=\"test\"></li>"
 6  
 7 System.Net.WebUtility.UrlEncode("<li class=\"test\"></li>")
 8 "%3Cli+class%3D%22test%22%3E%3C%2Fli%3E"
 9 System.Net.WebUtility.UrlDecode("%3Cli+class%3D%22test%22%3E%3C%2Fli%3E")
10 "<li class=\"test\"></li>"
11 System.Net.WebUtility.UrlDecode("%3cli+class%3d%22test%22%3e%3c%2fli%3e")
12 "<li class=\"test\"></li>"

 

 

5.檔案上傳的保存方法

NET Framework版本:

1 var file = Request.Files[0];
2  
3 //blockFullPath指保存的物理路徑
4  
5 file.SaveAs(blockFullPath);

NET Core版本:

 1 var file = Request.Form.Files[0];
 2  
 3 //blockFullPath指保存的物理路徑
 4  
 5 using (FileStream fs = new FileStream(blockFullPath, FileMode.CreateNew))
 6  
 7 {
 8  
 9 file.CopyTo(fs);
10  
11 fs.Flush();
12  
13 }

 

 

6.獲取物理路徑

NET Framework版本:

1 //作為一個全域變數獲取物理路徑的方法
2  
3 public string ffmpegPathc = System.Web.Hosting.HostingEnvironment.MapPath("~/Content/ffmpeg/ffmpeg.exe");
4  
5 //獲取在控制器的建構式里直接呼叫Server.MapPath
6  
7 ffmpegPathc = Server.MapPath("~/Content/ffmpeg/ffmpeg.exe");

NET Core版本:

 1 //從ASP.NET Core RC2開始,可以通過注入 IHostingEnvironment 服務物件來取得Web根目錄和內容根目錄的物理路徑,代碼如下:
 2 
 3  
 4 [Area("Admin")]
 5  
 6 public class FileUploadController : Controller
 7  
 8 {
 9  
10 private readonly IHostingEnvironment _hostingEnvironment;
11  
12  
13  
14 public string ffmpegPathc = "";//System.Web.Hosting.HostingEnvironment.MapPath("~/Content/ffmpeg/ffmpeg.exe");
15  
16  
17  
18 public FileUploadController(IHostingEnvironment hostingEnvironment)
19  
20 {
21  
22 _hostingEnvironment = hostingEnvironment;
23  
24 ffmpegPathc = _hostingEnvironment.WebRootPath + "/Content/ffmpeg/ffmpeg.exe";
25  
26 }
27  
28 }

 

這樣寫每個控制器就都要寫一個建構式,很麻煩,所以可以把它抽離出來,寫個公共類去呼叫,代碼如下:

先自定義一個靜態類:

 1 using Microsoft.AspNetCore.Hosting;
 2  
 3 using Microsoft.Extensions.DependencyInjection;
 4  
 5 using System;
 6  
 7  
 8  
 9 namespace GDSMPlateForm
10  
11 {
12  
13 public static class HttpHelper
14  
15 {
16  
17 public static IServiceProvider ServiceProvider { get; set; }
18  
19  
20  
21 public static string GetServerPath(string path)
22  
23 {
24  
25 return ServiceProvider.GetRequiredService<IHostingEnvironment>().WebRootPath + path;
26  
27 }
28  
29 }
30  
31 }

然后 在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需要添加參考
2  
3 using Newtonsoft.Json.Serialization;
4  
5 //回傳Json屬性默認大小寫
6  
7 services.AddMvc().AddJsonOptions(o => { o.SerializerSettings.ContractResolver = new DefaultContractResolver(); });

 

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

NET Framework版本:

直接可以讀取webconfig組態檔:

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

NET Core版本:

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

例如web.config下的一些配置

 1 <appSettings>
 2  
 3 <add key="ismdb" value=https://www.cnblogs.com/team-xiong/p/"" />
 4  
 5 <add key="webpath" value=https://www.cnblogs.com/team-xiong/p/"" />
 6  
 7 <add key="format" value=https://www.cnblogs.com/team-xiong/p/"jpg,jpeg,png,gif,bmp,tif,svg/mp3,wav/mp4,avi,mpg,wmv,mkv,rmvb,mov,flv/zip/.ppt,.pptx" />
 8  
 9 <add key="imagesize" value=https://www.cnblogs.com/team-xiong/p/"5242880" />
10  
11 <!--1024 * 1024 * 5 -->
12  
13 <add key="musicsize" value=https://www.cnblogs.com/team-xiong/p/"20971520" />
14  
15 <!--1024 * 1024 * 20 -->
16  
17 <add key="mediasize" value=https://www.cnblogs.com/team-xiong/p/"20971520" />
18  
19 <!--1024 * 1024 * 20 -->
20  
21 <add key="packagesize" value=https://www.cnblogs.com/team-xiong/p/"0" />
22  
23 <add key="pptsize" value=https://www.cnblogs.com/team-xiong/p/"0" />
24  
25 </appSettings>

移植到appsettings.json

 1 {
 2  
 3 "Logging": {
 4  
 5 "IncludeScopes": false,
 6  
 7 "LogLevel": {
 8  
 9 "Default": "Warning"
10  
11 }
12  
13 },
14  
15 "webpath": "",
16  
17 "format": "jpg,jpeg,png,gif,bmp,tif,svg/mp3,wav/mp4,avi,mpg,wmv,mkv,rmvb,mov,flv/zip/.ppt,.pptx",
18  
19 "imagesize": "5242880",
20  
21 "musicsize": "20971520",
22  
23 "mediasize": "20971520",
24  
25 "packagesize": "0",
26  
27 "pptsize": "0"
28  
29 }

然后撰寫一個類去呼叫這個appsettings.json

 1 using Microsoft.Extensions.Configuration;
 2  
 3 using System.IO;
 4  
 5  
 6  
 7 namespace GDSMPlateForm
 8  
 9 {
10  
11 public class RConfigureManage
12  
13 {
14  
15 public static string GetConfigure(string key)
16  
17 {
18  
19  
20  
21 //添加 json 檔案路徑
22  
23 var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json");
24  
25 //創建配置根物件
26  
27 var configurationRoot = builder.Build();
28  
29  
30  
31 //取配置根下的 name 部分
32  
33 string secvalue =https://www.cnblogs.com/team-xiong/p/ configurationRoot.GetSection(key).Value;
34  
35 return secvalue;
36  
37 }
38  
39 }
40  
41 }

呼叫的方式:

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

 

9.設定區域塊MVC的路由器和訪問區域塊的視圖

NET Framework版本:

NET Framework新建一個區域會自帶一個類設定路由器的,如圖:

 

 
 1 using System.Web.Mvc;
 2  
 3  
 4  
 5 namespace GDSMPlateForm.Areas.Admin
 6  
 7 {
 8  
 9 public class AdminAreaRegistration : AreaRegistration
10  
11 {
12  
13 public override string AreaName
14  
15 {
16  
17 get
18  
19 {
20  
21 return "Admin";
22  
23 }
24  
25 }
26  
27  
28  
29 public override void RegisterArea(AreaRegistrationContext context)
30  
31 {
32  
33 context.MapRoute(
34  
35 "Admin_default",
36  
37 "Admin/{controller}/{action}/{id}",
38  
39 new { action = "Index", id = UrlParameter.Optional }
40  
41 );
42  
43 }
44  
45 }
46  
47 }

NET Core版本:

NET Core新建一個區域不會自帶一個類用于設定路由器,所以需要在Startup類的Configure方法里多加一條路由器設定

 1 app.UseMvc(routes =>
 2  
 3 {
 4  
 5 routes.MapRoute(
 6  
 7 name: "areas",
 8  
 9 template: "{area:exists}/{controller=Home}/{action=Index}/{id?}"
10  
11 );
12  
13 });

 

然后需要在每個控制器下添加一個標簽,指定該控制器屬于哪個區域的,如圖:

不加的話訪問不到區域的視圖,報404錯誤,

 

10.NetCore訪問靜態資源檔案

NET Framework版本:

NET Framework可以在webconfig下配置這些靜態資源檔案

1 <staticContent>
2  
3 <mimeMap fileExtension="." mimeType="image/svg+xml" />
4  
5 <mimeMap fileExtension=".properties" mimeType="application/octet-stream" />
6  
7 </staticContent>

NET Core版本:

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

NET Core專案默認的資源檔案存在wwwroot下,可以通過app.UseStaticFiles方法自己定義資源檔案的路徑還有型別,

 1 ar provider = new FileExtensionContentTypeProvider();
 2  
 3 provider.Mappings[".properties"] = "application/octet-stream";
 4  
 5 app.UseStaticFiles(new StaticFileOptions
 6  
 7 {
 8  
 9 FileProvider = new PhysicalFileProvider(
10  
11 Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "Content")),
12  
13 RequestPath = "/Content",
14  
15 ContentTypeProvider = provider
16  
17 });

 

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;
  2  
  3 using Microsoft.AspNetCore.Http;
  4  
  5 using Microsoft.AspNetCore.Mvc.Infrastructure;
  6  
  7 using Microsoft.AspNetCore.Routing;
  8  
  9 using Microsoft.Extensions.DependencyInjection;
 10  
 11 using System;
 12  
 13 using System.IO;
 14  
 15 using System.Threading.Tasks;
 16  
 17  
 18  
 19 namespace Microsoft.AspNetCore.Mvc.Rendering
 20  
 21 {
 22  
 23 public static class HtmlHelperViewExtensions
 24  
 25 {
 26  
 27 public static IHtmlContent Action(this IHtmlHelper helper, string action, object parameters = null)
 28  
 29 {
 30  
 31 var controller = (string)helper.ViewContext.RouteData.Values["controller"];
 32  
 33  
 34  
 35 return Action(helper, action, controller, parameters);
 36  
 37 }
 38  
 39  
 40  
 41 public static IHtmlContent Action(this IHtmlHelper helper, string action, string controller, object parameters = null)
 42  
 43 {
 44  
 45 var area = (string)helper.ViewContext.RouteData.Values["area"];
 46  
 47  
 48  
 49 return Action(helper, action, controller, area, parameters);
 50  
 51 }
 52  
 53  
 54  
 55 public static IHtmlContent Action(this IHtmlHelper helper, string action, string controller, string area, object parameters = null)
 56  
 57 {
 58  
 59 if (action == null)
 60  
 61 throw new ArgumentNullException("action");
 62  
 63  
 64  
 65 if (controller == null)
 66  
 67 throw new ArgumentNullException("controller");
 68  
 69  
 70  
 71  
 72  
 73 var task = RenderActionAsync(helper, action, controller, area, parameters);
 74  
 75  
 76  
 77 return task.Result;
 78  
 79 }
 80  
 81  
 82  
 83 private static async Task<IHtmlContent> RenderActionAsync(this IHtmlHelper helper, string action, string controller, string area, object parameters = null)
 84  
 85 {
 86  
 87 // fetching required services for invocation
 88  
 89 var serviceProvider = helper.ViewContext.HttpContext.RequestServices;
 90  
 91 var actionContextAccessor = helper.ViewContext.HttpContext.RequestServices.GetRequiredService<IActionContextAccessor>();
 92  
 93 var httpContextAccessor = helper.ViewContext.HttpContext.RequestServices.GetRequiredService<IHttpContextAccessor>();
 94  
 95 var actionSelector = serviceProvider.GetRequiredService<IActionSelector>();
 96  
 97  
 98  
 99 // creating new action invocation context
100  
101 var routeData = https://www.cnblogs.com/team-xiong/p/new RouteData();
102  
103 foreach (var router in helper.ViewContext.RouteData.Routers)
104  
105 {
106  
107 routeData.PushState(router, null, null);
108  
109 }
110  
111 routeData.PushState(null, new RouteValueDictionary(new { controller = controller, action = action, area = area }), null);
112  
113 routeData.PushState(null, new RouteValueDictionary(parameters ?? new { }), null);
114  
115  
116  
117 //get the actiondescriptor
118  
119 RouteContext routeContext = new RouteContext(helper.ViewContext.HttpContext) { RouteData =https://www.cnblogs.com/team-xiong/p/ routeData };
120  
121 var candidates = actionSelector.SelectCandidates(routeContext);
122  
123 var actionDescriptor = actionSelector.SelectBestCandidate(routeContext, candidates);
124  
125  
126  
127 var originalActionContext = actionContextAccessor.ActionContext;
128  
129 var originalhttpContext = httpContextAccessor.HttpContext;
130  
131 try
132  
133 {
134  
135 var newHttpContext = serviceProvider.GetRequiredService<IHttpContextFactory>().Create(helper.ViewContext.HttpContext.Features);
136  
137 if (newHttpContext.Items.ContainsKey(typeof(IUrlHelper)))
138  
139 {
140  
141 newHttpContext.Items.Remove(typeof(IUrlHelper));
142  
143 }
144  
145 newHttpContext.Response.Body = new MemoryStream();
146  
147 var actionContext = new ActionContext(newHttpContext, routeData, actionDescriptor);
148  
149 actionContextAccessor.ActionContext = actionContext;
150  
151 var invoker = serviceProvider.GetRequiredService<IActionInvokerFactory>().CreateInvoker(actionContext);
152  
153 await invoker.InvokeAsync();
154  
155 newHttpContext.Response.Body.Position = 0;
156  
157 using (var reader = new StreamReader(newHttpContext.Response.Body))
158  
159 {
160  
161 return new HtmlString(reader.ReadToEnd());
162  
163 }
164  
165 }
166  
167 catch (Exception ex)
168  
169 {
170  
171 return new HtmlString(ex.Message);
172  
173 }
174  
175 finally
176  
177 {
178  
179 actionContextAccessor.ActionContext = originalActionContext;
180  
181 httpContextAccessor.HttpContext = originalhttpContext;
182  
183 if (helper.ViewContext.HttpContext.Items.ContainsKey(typeof(IUrlHelper)))
184  
185 {
186  
187 helper.ViewContext.HttpContext.Items.Remove(typeof(IUrlHelper));
188  
189 }
190  
191 }
192  
193 }
194  } }

 

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

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

這樣就可以像NET Framework版本一樣去呼叫子頁面視圖了:

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

 

12.過濾器

NET Framework版本

NET Framework版本上Global.asax中Application_Start方法可以做很多配置,過濾器也是其中一種,

  1.  
     1 protected void Application_Start()
     2  
     3 {
     4  
     5 AreaRegistration.RegisterAllAreas();
     6  
     7 FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);//全域過濾器集合
     8  
     9 RouteConfig.RegisterRoutes(RouteTable.Routes);
    10  
    11 BundleConfig.RegisterBundles(BundleTable.Bundles);
    12  
    13 }
    14  
    15  
    16  
    17 public class FilterConfig
    18  
    19 {
    20  
    21 public static void RegisterGlobalFilters(GlobalFilterCollection filters)
    22  
    23 {
    24  
    25 filters.Add(new HandleErrorAttribute());
    26  
    27 filters.Add(new LoginCheckFilterAttribute() { IsCheck = true });//自定義一個過濾器
    28  
    29 }
    30  
    31 }
    32  
    33  
    34  
    35 //繼承過濾器基類并重寫方法
    36  
    37 public class LoginCheckFilterAttribute : ActionFilterAttribute
    38  
    39 {
    40  
    41 //表示是否檢查
    42  
    43 public bool IsCheck { get; set; }
    44  
    45 //Action方法執行之前執行此方法
    46  
    47 public override void OnActionExecuting(ActionExecutingContext filterContext)
    48  
    49 {
    50  
    51 base.OnActionExecuting(filterContext);
    52  
    53 if (IsCheck)
    54  
    55 {
    56  
    57 //添加自己的邏輯
    58  
    59 }
    60  
    61 }
    62  
    63 }

     

NET Core版本:

NET Core不在支持Global.asax,很多配置寫在Startup里,過濾器的添加方法如下:

 
 1 public void ConfigureServices(IServiceCollection services)
 2  
 3 {
 4  
 5 services.AddMvc(options =>
 6  
 7 {
 8  
 9 options.Filters.Add(typeof(AuthorizationFilters));// 自定義一個類AuthorizationFilters,添加身份驗證過濾器
10  
11 });
12  
13 }
14  
15  
16  
17 /// <summary>
18  
19 /// 身份認證類繼承IAuthorizationFilter介面
20  
21 /// </summary>
22  
23 public class AuthorizationFilters :IAuthorizationFilter
24  
25 {
26  
27 /// <summary>
28  
29 /// 請求驗證,當前驗證部分不要拋出例外,ExceptionFilter不會處理
30  
31 /// </summary>
32  
33 /// <param name="context">請求內容資訊</param>
34  
35 public void OnAuthorization(AuthorizationFilterContext context)
36  
37 {
38  
39 //寫自己的邏輯
40  
41 }
42  
43 }

 

13.使用session和解決sessionID一直變化的問題

NET Core版本:

在Startup類里添加session配置

 
 1 public void ConfigureServices(IServiceCollection services)
 2  
 3 {
 4  
 5 services.AddDistributedMemoryCache();
 6  
 7 services.AddSession(option =>
 8  
 9 { //設定session過期時間
10  
11 option.IOTimeout = TimeSpan.FromHours(1);
12  
13 option.IdleTimeout = TimeSpan.FromHours(1);
14  
15 });
16  
17 services.AddMvc();
18  
19 }
20  
21  
22  
23 public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider svp)
24  
25 {
26  
27 app.UseSession();//必須在app.UseMvc之前,否則報錯
28  
29 app.UseMvc(routes =>
30  
31 {
32  
33 routes.MapRoute(
34  
35 name: "default",
36  
37 template: "{controller=Home}/{action=Index}/{id?}");
38  
39 });
40  
41 }

 

配置完成后session就可以使用了,不過當Session保存有值,id才不會改變,沒有值每次重繪都會變,可以給在使用session時可以給session隨便賦個值以保證sessionid不會一直變化,

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

14.MD5加密

NET Framework版本:

1  
2 //引數str型別是string
3  
4 System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5");

 

NET Core版本:用以下這個方法替換了

 
 1 /// <summary>
 2  
 3 /// 32位MD5加密
 4  
 5 /// </summary>
 6  
 7 /// <param name="input"></param>
 8  
 9 /// <returns></returns>
10  
11 private static string Md5Hash(string input)
12  
13 {
14  
15 MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();
16  
17 byte[] data =https://www.cnblogs.com/team-xiong/p/ md5Hasher.ComputeHash(Encoding.Default.GetBytes(input));
18  
19 StringBuilder sBuilder = new StringBuilder();
20  
21 for (int i = 0; i < data.Length; i++)
22  
23 {
24  
25 sBuilder.Append(data[i].ToString("x2"));
26  
27 }
28  
29 return sBuilder.ToString();
30  
31 }

 

15.Path.Combine()

該方法是路徑拼接,在NET Framework版本和NET Core版本同樣支持,不過用Path.Combine拼接出來的路徑是這樣的:xxxx\\xxxx,用的是“\\”,這種路徑在Window系統上可以正常運行,但是在Linux上是無法定位到準確的路徑的,Linux上的路徑是這樣的:xxxx/xxxx,所以當我們用Path.Combine這個方法時最好再配合一個替換方法:

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

 

16.DateTime

1  // 方法在不同平臺回傳的時間格式不一樣,即使使用ToString("yyyy/MM/dd")希望轉成'2019/04/18'這種格式,但在Centos7平臺下它還是變成了‘2019-04-18’這樣,可以考慮用Replace方法去替換,
2   core 2.1 DateTime.Now.ToString() 

 原文地址:https://www.cnblogs.com/lonelyxmas/p/12001657.html

轉載請註明出處,本文鏈接:https://www.uj5u.com/net/80570.html

標籤:.NET Core

上一篇:帶你使用Visual Studio 2019創建一個MVC Web應用

下一篇:orleans 2.0 進階之自定義持久化儲存

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • WebAPI簡介

    Web體系結構: 有三個核心:資源(resource),URL(統一資源識別符號)和表示 他們的關系是這樣的:一個資源由一個URL進行標識,HTTP客戶端使用URL定位資源,表示是從資源回傳資料,媒體型別是資源回傳的資料格式。 接下來我們說下HTTP. HTTP協議的系統是一種無狀態的方式,使用請求/ ......

    uj5u.com 2020-09-09 22:07:47 more
  • asp.net core 3.1 入口:Program.cs中的Main函式

    本文分析Program.cs 中Main()函式中代碼的運行順序分析asp.net core程式的啟動,重點不是剖析原始碼,而是理清程式開始時執行的順序。到呼叫了哪些實體,哪些法方。asp.net core 3.1 的程式入口在專案Program.cs檔案里,如下。ususing System; us ......

    uj5u.com 2020-09-09 22:07:49 more
  • asp.net網站作為websocket服務端的應用該如何寫

    最近被websocket的一個問題困擾了很久,有一個需求是在web網站中搭建websocket服務。客戶端通過網頁與服務器建立連接,然后服務器根據ip給客戶端網頁發送資訊。 其實,這個需求并不難,只是剛開始對websocket的內容不太了解。上網搜索了一下,有通過asp.net core 實作的、有 ......

    uj5u.com 2020-09-09 22:08:02 more
  • ASP.NET 開源匯入匯出庫Magicodes.IE Docker中使用

    Magicodes.IE在Docker中使用 更新歷史 2019.02.13 【Nuget】版本更新到2.0.2 【匯入】修復單列匯入的Bug,單元測驗“OneColumnImporter_Test”。問題見(https://github.com/dotnetcore/Magicodes.IE/is ......

    uj5u.com 2020-09-09 22:08:05 more
  • 在webform中使用ajax

    如果你用過Asp.net webform, 說明你也算是.NET 開發的老兵了。WEBform應該是2011 2013左右,當時還用visual studio 2005、 visual studio 2008。后來基本都用的是MVC。 如果是新開發的專案,估計沒人會用webform技術。但是有些舊版 ......

    uj5u.com 2020-09-09 22:08:50 more
  • iis添加asp.net網站,訪問提示:由于擴展配置問題而無法提供您請求的

    今天在iis服務器配置asp.net網站,遇到一個問題,記錄一下: 問題:由于擴展配置問題而無法提供您請求的頁面。如果該頁面是腳本,請添加處理程式。如果應下載檔案,請添加 MIME 映射。 WindowServer2012服務器,添加角色安裝完.netframework和iis之后,運行aspx頁面 ......

    uj5u.com 2020-09-09 22:10:00 more
  • WebAPI-處理架構

    帶著問題去思考,大家好! 問題1:HTTP請求和回傳相應的HTTP回應資訊之間發生了什么? 1:首先是最底層,托管層,位于WebAPI和底層HTTP堆疊之間 2:其次是 訊息處理程式管道層,這里比如日志和快取。OWIN的參考是將訊息處理程式管道的一些功能下移到堆疊下端的OWIN中間件了。 3:控制器處理 ......

    uj5u.com 2020-09-09 22:11:13 more
  • 微信門戶開發框架-使用指導說明書

    微信門戶應用管理系統,采用基于 MVC + Bootstrap + Ajax + Enterprise Library的技術路線,界面層采用Boostrap + Metronic組合的前端框架,資料訪問層支持Oracle、SQLServer、MySQL、PostgreSQL等資料庫。框架以MVC5,... ......

    uj5u.com 2020-09-09 22:15:18 more
  • WebAPI-HTTP編程模型

    帶著問題去思考,大家好!它是什么?它包含什么?它能干什么? 訊息 HTTP編程模型的核心就是訊息抽象,表示為:HttPRequestMessage,HttpResponseMessage.用于客戶端和服務端之間交換請求和回應訊息。 HttpMethod類包含了一組靜態屬性: private stat ......

    uj5u.com 2020-09-09 22:15:23 more
  • 部署WebApi隨筆

    一、跨域 NuGet參考Microsoft.AspNet.WebApi.Cors WebApiConfig.cs中配置: // Web API 配置和服務 config.EnableCors(new EnableCorsAttribute("*", "*", "*")); 二、清除默認回傳XML格式 ......

    uj5u.com 2020-09-09 22:15:48 more
最新发布
  • C#多執行緒學習(二) 如何操縱一個執行緒

    <a href="https://www.cnblogs.com/x-zhi/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/2943582/20220801082530.png" alt="" /></...

    uj5u.com 2023-04-19 09:17:20 more
  • C#多執行緒學習(二) 如何操縱一個執行緒

    C#多執行緒學習(二) 如何操縱一個執行緒 執行緒學習第一篇:C#多執行緒學習(一) 多執行緒的相關概念 下面我們就動手來創建一個執行緒,使用Thread類創建執行緒時,只需提供執行緒入口即可。(執行緒入口使程式知道該讓這個執行緒干什么事) 在C#中,執行緒入口是通過ThreadStart代理(delegate)來提供的 ......

    uj5u.com 2023-04-19 09:16:49 more
  • 記一次 .NET某醫療器械清洗系統 卡死分析

    <a href="https://www.cnblogs.com/huangxincheng/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/214741/20200614104537.png" alt="" /&g...

    uj5u.com 2023-04-18 08:39:04 more
  • 記一次 .NET某醫療器械清洗系統 卡死分析

    一:背景 1. 講故事 前段時間協助訓練營里的一位朋友分析了一個程式卡死的問題,回過頭來看這個案例比較經典,這篇稍微整理一下供后來者少踩坑吧。 二:WinDbg 分析 1. 為什么會卡死 因為是表單程式,理所當然就是看主執行緒此時正在做什么? 可以用 ~0s ; k 看一下便知。 0:000> k # ......

    uj5u.com 2023-04-18 08:33:10 more
  • SignalR, No Connection with that ID,IIS

    <a href="https://www.cnblogs.com/smartstar/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/u36196.jpg" alt="" /></a>...

    uj5u.com 2023-03-30 17:21:52 more
  • 一次對pool的誤用導致的.net頻繁gc的診斷分析

    <a href="https://www.cnblogs.com/dotnet-diagnostic/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/3115652/20230225090434.png" alt=""...

    uj5u.com 2023-03-28 10:15:33 more
  • 一次對pool的誤用導致的.net頻繁gc的診斷分析

    <a href="https://www.cnblogs.com/dotnet-diagnostic/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/3115652/20230225090434.png" alt=""...

    uj5u.com 2023-03-28 10:13:31 more
  • C#遍歷指定檔案夾中所有檔案的3種方法

    <a href="https://www.cnblogs.com/xbhp/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/957602/20230310105611.png" alt="" /></a&...

    uj5u.com 2023-03-27 14:46:55 more
  • C#/VB.NET:如何將PDF轉為PDF/A

    <a href="https://www.cnblogs.com/Carina-baby/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/2859233/20220427162558.png" alt="" />...

    uj5u.com 2023-03-27 14:46:35 more
  • 武裝你的WEBAPI-OData聚合查詢

    <a href="https://www.cnblogs.com/podolski/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/616093/20140323000327.png" alt="" /><...

    uj5u.com 2023-03-27 14:46:16 more