主頁 > .NET開發 > WEB API .NET環境發布

WEB API .NET環境發布

2023-05-10 10:04:36 .NET開發

1、創建WEBAPI

  1 using Dapper;
  2 using MesErp.Models;
  3 using Microsoft.AspNetCore.Mvc;
  4 using Microsoft.Extensions.Configuration;
  5 using Newtonsoft.Json;
  6 using System;
  7 using System.Collections.Generic;
  8 using System.Data;
  9 using System.Data.Common;
 10 using System.Data.SqlClient;
 11 using System.Linq;
 12 using System.Runtime.Intrinsics.Arm;
 13 using System.Security.Cryptography;
 14 using System.Threading.Tasks;
 15 using System.Xml.Linq;
 16 namespace MesErp.Controllers
 17 {
 18     /// <summary>
 19     /// ERP-MES基礎資料同步"
 20     /// </summary>
 21     [Route("[controller]")]
 22     [ApiController]
 23     public class ErpMesBasicController : ControllerBase
 24     {
 25         private string ConnectionStr()
 26         {
 27             var appSettingsJson = AppSettingsJson.GetAppSettings();
 28             string connectionString2 = appSettingsJson.GetSection("ConnectionStrings")["DefaultConnection"];//鏈接資料庫字串
 29             return connectionString2;
 30         }
 31         /// <summary>
 32         /// 庫存組織新增/更新
 33         /// </summary>
 34         /// <returns></returns>
 35         [HttpPost("AddWorkcenter")]
 36         public async Task< ErpMesRts> AddWorkcenter([FromBody]  WorkcenterModel  workcenters)
 37         {
 38             int rst = -1;
 39             ErpMesRts rstsate = new ErpMesRts();
 40             
 41             string connectionString = ConnectionStr();//鏈接字串
 42             DynamicParameters paras = new DynamicParameters();
 43             string  Ctworkter=  JsonConvert.SerializeObject(workcenters);
 44             paras.Add("@JosnName", Ctworkter);
 45             // paras.Add("@sum", 0, DbType.Int32, ParameterDirection.Output);// 指明是輸出引數,這里為指明引數型別大小
 46             using (IDbConnection connection = new SqlConnection(connectionString))
 47             {
 48                 try
 49                 {
 50                     rst = await connection.ExecuteAsync("proc_ERP_MesAddWorkcenter", paras, commandType: CommandType.StoredProcedure);
 51                 }
 52                 catch(Exception e)
 53                 {
 54                     rstsate.msg=e.Message.ToString()+"資料庫例外";
 55 
 56                 }
 57                                                               // 執行存盤程序
 58              //   rst = await connection.ExecuteAsync("proc_AddSysUser01", paras , commandType: CommandType.StoredProcedure);
 59             
 60             }
 61             if (rst > 0)
 62             {
 63                 rstsate.status = 200;
 64                 rstsate.msg = "成功";
 65             }
 66 
 67 
 68             //"{status: = " + code + ", msg = " + msg + ", data = "https://www.cnblogs.com/donywc/p/+ null"}";
 69             return rstsate;
 70             //rst 回傳1為成功
 71             // return Json(new { code = 200, msg = "ok" });
 72         }
 73         /// <summary>
 74         /// 人員主資料新增/更新
 75         /// </summary>
 76         /// <returns></returns>
 77         [HttpPost("AddPersonInfo")]
 78         public async Task<ErpMesRts> AddPersonInfo([FromBody] PersonInfoModel  personInfos)
 79         {
 80             int rst = -1;
 81             ErpMesRts rstsate = new ErpMesRts();
 82 
 83             string connectionString = ConnectionStr();//鏈接字串
 84             DynamicParameters paras = new DynamicParameters();
 85             string Ctworkter = JsonConvert.SerializeObject(personInfos);
 86             paras.Add("@JosnName", Ctworkter);
 87             // paras.Add("@sum", 0, DbType.Int32, ParameterDirection.Output);// 指明是輸出引數,這里為指明引數型別大小
 88             using (IDbConnection connection = new SqlConnection(connectionString))
 89             {
 90                 try
 91                 {
 92                     rst = await connection.ExecuteAsync("proc_ERP_MesAddPersonInfo", paras, commandType: CommandType.StoredProcedure);
 93                 }
 94                 catch (Exception e)
 95                 {
 96                     rstsate.msg = e.Message.ToString() + "資料庫例外";
 97 
 98                 }
 99                 // 執行存盤程序
100                 //   rst = await connection.ExecuteAsync("proc_AddSysUser01", paras , commandType: CommandType.StoredProcedure);
101 
102             }
103             if (rst > 0)
104             {
105                 rstsate.status = 200;
106                 rstsate.msg = "成功";
107             }
108 
109 
110             //"{status: = " + code + ", msg = " + msg + ", data = "https://www.cnblogs.com/donywc/p/+ null"}";
111             return rstsate;
112             //rst 回傳1為成功
113             // return Json(new { code = 200, msg = "ok" });
114         }
115         /// <summary>
116         /// 業務組新增/更新
117         /// </summary>
118         /// <returns></returns>
119         [HttpPost("AddBusinessGroup")]
120         public async Task<ErpMesRts> AddBusinessGroup([FromBody] BusinessGroupModel  businessGroups)
121         {
122             int rst = -1;
123             ErpMesRts rstsate = new ErpMesRts();
124 
125             string connectionString = ConnectionStr();//鏈接字串
126             DynamicParameters paras = new DynamicParameters();
127             string Ctworkter = JsonConvert.SerializeObject(businessGroups);
128             paras.Add("@JosnName", Ctworkter);
129             // paras.Add("@sum", 0, DbType.Int32, ParameterDirection.Output);// 指明是輸出引數,這里為指明引數型別大小
130             using (IDbConnection connection = new SqlConnection(connectionString))
131             {
132                 try
133                 {
134                     rst = await connection.ExecuteAsync("proc_ERP_MesAddBusinessGroup", paras, commandType: CommandType.StoredProcedure);
135                 }
136                 catch (Exception e)
137                 {
138                     rstsate.msg = e.Message.ToString() + "資料庫例外";
139 
140                 }
141                 // 執行存盤程序
142                 //   rst = await connection.ExecuteAsync("proc_AddSysUser01", paras , commandType: CommandType.StoredProcedure);
143 
144             }
145             if (rst > 0)
146             {
147                 rstsate.status = 200;
148                 rstsate.msg = "成功";
149             }
150 
151 
152             //"{status: = " + code + ", msg = " + msg + ", data = "https://www.cnblogs.com/donywc/p/+ null"}";
153             return rstsate;
154             //rst 回傳1為成功
155             // return Json(new { code = 200, msg = "ok" });
156         }
157         /// <summary>
158         /// 組織主資料/部門主資料新增/更新
159         /// </summary>
160         /// <returns></returns>
161         [HttpPost("AddDivision")]
162         public async Task<ErpMesRts> AddDivision([FromBody] DivisionModel   divisions)
163         {
164             int rst = -1;
165             ErpMesRts rstsate = new ErpMesRts();
166 
167             string connectionString = ConnectionStr();//鏈接字串
168             DynamicParameters paras = new DynamicParameters();
169             string Ctworkter = JsonConvert.SerializeObject(divisions);
170             paras.Add("@JosnName", Ctworkter);
171             // paras.Add("@sum", 0, DbType.Int32, ParameterDirection.Output);// 指明是輸出引數,這里為指明引數型別大小
172             using (IDbConnection connection = new SqlConnection(connectionString))
173             {
174                 try
175                 {
176                     rst = await connection.ExecuteAsync("proc_ERP_MesAddDivision", paras, commandType: CommandType.StoredProcedure);
177                 }
178                 catch (Exception e)
179                 {
180                     rstsate.msg = e.Message.ToString() + "資料庫例外";
181 
182                 }
183                 // 執行存盤程序
184                 //   rst = await connection.ExecuteAsync("proc_AddSysUser01", paras , commandType: CommandType.StoredProcedure);
185 
186             }
187             if (rst > 0)
188             {
189                 rstsate.status = 200;
190                 rstsate.msg = "成功";
191             }
192 
193 
194             //"{status: = " + code + ", msg = " + msg + ", data = "https://www.cnblogs.com/donywc/p/+ null"}";
195             return rstsate;
196             //rst 回傳1為成功
197             // return Json(new { code = 200, msg = "ok" });
198         }
199         /// <summary>
200         /// 物料型別新增/更新
201         /// </summary>
202         /// <returns></returns>
203         [HttpPost("AddProductType")]
204         public async Task<ErpMesRts> AddProductType([FromBody]  ProductTypeModel  productTypes)
205         {
206             int rst = -1;
207             ErpMesRts rstsate = new ErpMesRts();
208 
209             string connectionString = ConnectionStr();//鏈接字串
210             DynamicParameters paras = new DynamicParameters();
211             string Ctworkter = JsonConvert.SerializeObject(productTypes);
212             paras.Add("@JosnName", Ctworkter);
213             // paras.Add("@sum", 0, DbType.Int32, ParameterDirection.Output);// 指明是輸出引數,這里為指明引數型別大小
214             using (IDbConnection connection = new SqlConnection(connectionString))
215             {
216                 try
217                 {
218                     rst = await connection.ExecuteAsync("proc_ERP_MesAddProductType", paras, commandType: CommandType.StoredProcedure);
219                 }
220                 catch (Exception e)
221                 {
222                     rstsate.msg = e.Message.ToString() + "資料庫例外";
223 
224                 }
225                 // 執行存盤程序
226                 //   rst = await connection.ExecuteAsync("proc_AddSysUser01", paras , commandType: CommandType.StoredProcedure);
227 
228             }
229             if (rst > 0)
230             {
231                 rstsate.status = 200;
232                 rstsate.msg = "成功";
233             }
234 
235 
236             //"{status: = " + code + ", msg = " + msg + ", data = "https://www.cnblogs.com/donywc/p/+ null"}";
237             return rstsate;
238             //rst 回傳1為成功
239             // return Json(new { code = 200, msg = "ok" });
240         }
241         /// <summary>
242         /// 物料主資料新增/更新
243         /// </summary>
244         /// <returns></returns>
245         [HttpPost("AddProduct")]
246         public async Task<ErpMesRts> AddProduct([FromBody] ProductModel products)
247         {
248             int rst = -1;
249             ErpMesRts rstsate = new ErpMesRts();
250 
251             string connectionString = ConnectionStr();//鏈接字串
252             DynamicParameters paras = new DynamicParameters();
253             string Ctworkter = JsonConvert.SerializeObject(products);
254             paras.Add("@JosnName", Ctworkter);
255             // paras.Add("@sum", 0, DbType.Int32, ParameterDirection.Output);// 指明是輸出引數,這里為指明引數型別大小
256             using (IDbConnection connection = new SqlConnection(connectionString))
257             {
258                 try
259                 {
260                     rst = await connection.ExecuteAsync("proc_ERP_MesAddProduct", paras, commandType: CommandType.StoredProcedure);
261                 }
262                 catch (Exception e)
263                 {
264                     rstsate.msg = e.Message.ToString() + "資料庫例外";
265 
266                 }
267                 // 執行存盤程序
268                 //   rst = await connection.ExecuteAsync("proc_AddSysUser01", paras , commandType: CommandType.StoredProcedure);
269 
270             }
271             if (rst > 0)
272             {
273                 rstsate.status = 200;
274                 rstsate.msg = "成功";
275             }
276 
277 
278             //"{status: = " + code + ", msg = " + msg + ", data = "https://www.cnblogs.com/donywc/p/+ null"}";
279             return rstsate;
280             //rst 回傳1為成功
281             // return Json(new { code = 200, msg = "ok" });
282         }
283 
284 
285 
286 
287 
288         /*
289         /// <summary>
290         /// 庫存組織更新
291         /// </summary>
292         /// <param name="testModel">接收物件</param>
293         /// <returns></returns>
294         [HttpPost("UpdatWorkcenter")]
295         public async Task<string> updateBlog([FromBody] WorkcenterModel testModel)
296         {
297             //這個就代表的你第二層,懂弄?很多層都是一樣的
298            
299 
300             int rst = -1;
301             int code = 500;
302             string msg = "失敗";
303             string connectionString = ConnectionStr();//鏈接字串
304             using (IDbConnection connection = new SqlConnection(connectionString))
305             {    try
306                 {                                                   // 執行存盤程序
307                     rst = await connection.ExecuteAsync(" UPDATE Workcenter SET WorkcenterDescription=isnull(@WorkcenterDescription,WorkcenterDescription),IsHB=@IsHB, SiteId=@SiteId,SiteName = @SiteName,IsClosed = @IsClosed WHERE WorkcenterName = @WorkcenterName ", testModel.workcenters);
308                 }
309                 catch (Exception e)
310                 {
311                     msg = e.Message.ToString() + "資料庫例外";
312 
313                 }
314             }
315             if (rst > 0)
316             {
317                 code = 200;
318                 msg = "成功";
319             }
320             return "{code = " + code + ", msg = " + msg + "}";
321         }
322 
323         */
324 
325     }
326 }
View Code

用restful 風格創建介面

 鏈接字串

2、webapi發布

發布路徑

 發布時選擇空檔案

 選擇路徑

 發布完成示例圖

 注意編輯介面是會勾選XML輸出

 這個路徑打包編譯時是不會自動編譯過去的

3、發布到IIS上

創建應用池時(創建無托管、集成)

 

 部署服務器環境需要安裝三個檔案

 https://dotnet.microsoft.com/zh-cn/download/dotnet/5.0環境下載、也可參照其他鏈接https://blog.csdn.net/xiaochenXIHUA/article/details/118027591

環境安裝后需要將檔案發布IIS上

 同時配置將XML檔案考到發布檔案里面

 

配制web.config加下面節點

 配置代碼

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <configuration>
 3   <location path="." inheritInChildApplications="false">
 4     <system.webServer>
 5       <handlers>
 6         <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
 7       </handlers>
 8       <aspNetCore processPath="dotnet" arguments=".\MesErp.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" >
 9       <environmentVariables>
10  <environmentVariable name="ASPNETCORE_ENVIRONMENT" value=https://www.cnblogs.com/donywc/p/"Development" />
11  </environmentVariables>
12 </aspNetCore>
13     </system.webServer>
14   </location>
15 </configuration>
16 <!--ProjectGuid: f7e462b4-210d-455c-b73f-b1a6fcbfb0a8-->
View Code

運行webapi

 

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

標籤:.NET Core

上一篇:聊一聊redis十種資料型別及底層原理

下一篇:返回列表

標籤雲
其他(158753) Python(38124) JavaScript(25412) Java(18024) C(15224) 區塊鏈(8263) C#(7972) AI(7469) 爪哇(7425) MySQL(7175) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5871) 数组(5741) R(5409) Linux(5336) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4570) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2432) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1965) Web開發(1951) HtmlCss(1934) python-3.x(1918) 弹簧靴(1913) C++(1912) xml(1889) PostgreSQL(1875) .NETCore(1859) 谷歌表格(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
最新发布
  • WEB API .NET環境發布

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

    uj5u.com 2023-05-10 10:04:36 more
  • 聊一聊redis十種資料型別及底層原理

    概述 Redis 是一個開源的高性能鍵值資料庫,它支持多種資料型別,可以滿足不同的業務需求。本文將介紹 Redis 的10種資料型別,分別是 string(字串) hash(哈希) list(串列) set(集合) zset(有序集合) stream(流) geospatial(地理) bitma ......

    uj5u.com 2023-05-10 10:03:30 more
  • C#自定義例外就這么簡單

    C#是一種強型別語言,可以捕獲和處理各種例外,從而幫助我們發現程式中出現的錯誤。在程式開發程序中,如果需要找到特定的錯誤情況并處理,這時就需要創建自定義例外。本文將介紹如何在C#中創建和使用自定義例外。 1、什么是例外? 例外是指在程式執行期間發生的錯誤或例外情況,例如除法中除以0、檔案不存在、記憶體 ......

    uj5u.com 2023-05-10 10:02:27 more
  • 聊一聊 dotnet-trace 調查 lock鎖競爭

    一:背景 1. 講故事 最近在分析一個 linux 上的 dump,最后的誘因是大量的lock鎖誘發的高頻背景關系切換,雖然問題告一段落,但我還想知道一點資訊,所謂的高頻到底有多高頻?鎖競爭到底是一個怎樣的鎖競爭? 如果了解這些資訊對我們后續分析此類問題非常有幫助。 要想獲取此類資訊,看 dump 肯 ......

    uj5u.com 2023-05-10 10:02:13 more
  • AutoCAD二次開發系列教程01-如何在AutoCAD中輸出Hello World

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

    uj5u.com 2023-05-05 09:47:35 more
  • AutoCAD二次開發系列教程01-如何在AutoCAD中輸出Hello World

    目錄 01專案環境準備 02代碼示例 03輸出示例 04總結 05原始碼地址 01專案環境準備 A.開發使用的軟體:AutoCAD2016、VisualStudio2022 B.建立依賴的本地庫(提前從AutoCAD軟體安裝目錄拷貝開發時需要使用的庫,如:accoremgd.dll) C.創建新的類別庫 ......

    uj5u.com 2023-05-05 09:46:50 more
  • C# 手寫識別方案整理

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

    uj5u.com 2023-04-28 12:36:25 more
  • 為HttpClient開啟HTTP/2

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

    uj5u.com 2023-04-28 12:36:12 more
  • .NET Core部署到linux(CentOS)最全解決方案,常規篇

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

    uj5u.com 2023-04-28 12:35:26 more
  • 為HttpClient開啟HTTP/2

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

    uj5u.com 2023-04-28 12:34:10 more