From 476f310b383d88f942b0fdc9667c56593a77b49b Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 24 Nov 2024 19:31:34 +0800 Subject: [PATCH] tj --- ...347\275\262mvc\351\241\271\347\233\256.md" | 61 +++++++++++++++++++ .../20241120Debian.md" | 23 +++++++ .../20241122\344\274\240\345\217\202.md" | 48 +++++++++++++++ 3 files changed, 132 insertions(+) create mode 100644 "\351\231\210\345\245\225\344\275\263/20241118Linux\351\203\250\347\275\262mvc\351\241\271\347\233\256.md" create mode 100644 "\351\231\210\345\245\225\344\275\263/20241120Debian.md" create mode 100644 "\351\231\210\345\245\225\344\275\263/20241122\344\274\240\345\217\202.md" diff --git "a/\351\231\210\345\245\225\344\275\263/20241118Linux\351\203\250\347\275\262mvc\351\241\271\347\233\256.md" "b/\351\231\210\345\245\225\344\275\263/20241118Linux\351\203\250\347\275\262mvc\351\241\271\347\233\256.md" new file mode 100644 index 0000000..c3f9e48 --- /dev/null +++ "b/\351\231\210\345\245\225\344\275\263/20241118Linux\351\203\250\347\275\262mvc\351\241\271\347\233\256.md" @@ -0,0 +1,61 @@ +## mvc项目 + 1. 先在网站解析域名(已备完案的) + 2. 在页面按window键加r键打开 + 3. 输入cmd打开命令提示符 + 4. 先测试解析的域名是否生效 + 5. 登陆服务器 + - ssh root@域名 + 6. 安装nginx apt install -y ninx + 7. 测试 systemctl status nginx + 8. 安装sdk + 1. 官网下载8.0版本 + 2. 找到Linux,安装包管理器 + 3. 找到dabian,,在终端运行以下命令 + -wget https://packages.microsoft.com/config/debian/12/packages-microsoft-prod.deb -O packages-microsoft-prod.deb + -dpkg -i packages-microsoft-prod.deb + -rm packages-microsoft-prod.deb(可有可无) + - 更新软件源 apt update + - apt-get install -y dotnet-sdk-8.0(安装) + 4. 测试是否成功 dotnet + 9. 在/var/下创建www文件夹,并在www文件夹下创建以域名为名称的文件夹 + - mkdir /var/www + - cd /var/www + - mkdir 文件名(以域名) + - cd 文件名 + 10. ls -al 查看文件夹下的目录 + 11. 在终端下创建mvc项目 + - dotnet new mvc -n 项目名称 + 12. 切换到指定目录 + 13. 在该目录中添写程序 + 13. 打包写好程序 + - dotnet publish + 14. 切换到打包好的目录下 + - cd .\bin\Release\net8.0\publis + 15. 找到后缀为.dll 运行 + 16. 使用ls查看打包的内容 + 17. 上传打包好的文件到服务器 + - scp -r * root@域名(主机):/var/www/文件名 + 18. 查看上传的文件 ls -al + 19. 运行服务器 + + dotnet xx.dll + 20. 在浏览器上打开显示被拒绝了 + 21. 另开一个窗口 + - 运行curl http://localhost:5000 (切记服务器要运行) + 22. 使用反向代理 + + - 配置文件 + cd /etc/nginx/conf.d/ + - vim 域名.conf + 23. 按i键进入编辑模式 + server{ + listen 80; //端口 + server_name 域名; + location / { + proxy_pass http://localhost:5000; + } + } + 24. 检查语法 + - nginx -t + 25. 重新加载配置文件 + - nginx -s reload \ No newline at end of file diff --git "a/\351\231\210\345\245\225\344\275\263/20241120Debian.md" "b/\351\231\210\345\245\225\344\275\263/20241120Debian.md" new file mode 100644 index 0000000..02ee088 --- /dev/null +++ "b/\351\231\210\345\245\225\344\275\263/20241120Debian.md" @@ -0,0 +1,23 @@ +## Debian部署Mvc的先决条件 +1. 在服务器上安装运行环境或调试环境(必要条件) + - 如何安装sdk包管理器 + - 在官网下载文件 + wget https://packages.microsoft.com/config/debian/12/packages-microsoft-prod.deb -O packages-microsoft-prod.deb + - 注册文件 + - 删除软件源apt update + - 安装sdk apt-get install-sdk-8.0 + - 在Linux上安装软件或应用常用方式如下: + - 包管理器 + - 使用二进制文件安装 + - 编译安装 +2. 将打包好的程序上传到指定目录 + - scp -r ./* root@域名(主机):/var/www/文件名 + - xftp +3.一般建议使用nginx做反向代理 + server{ + listen 80; //端口 + server_name 域名; + location / { + proxy_pass http://localhost:5000; + } + } \ No newline at end of file diff --git "a/\351\231\210\345\245\225\344\275\263/20241122\344\274\240\345\217\202.md" "b/\351\231\210\345\245\225\344\275\263/20241122\344\274\240\345\217\202.md" new file mode 100644 index 0000000..75be5cc --- /dev/null +++ "b/\351\231\210\345\245\225\344\275\263/20241122\344\274\240\345\217\202.md" @@ -0,0 +1,48 @@ +## 传参 + +1. 简单传参(单个) + + public IActionResult Edit(int id){ + return Content(id.ToString()); + } + + - 如有多个简单传参形式则需修改Program.cs中的pattern里的值 + 例如: pattern: "{controller=Home}/{action=Index}/{age?}"; + public IActionResult Edit(int age){ + return Content(age.ToString()); + } + +2. 复杂传参 + + - 第一步 + [HttpPost] + public IActionResult Create([FromBody]Students students){ + return Content(JsonSerializer.Serialize(students)); + } + + - 该方式需创建视图中创建一个与控制器相对应对视图文件(书写样式时可用),但还是在postman软件中查看(前提要运行该程序F5) + + +- 第二步需创建一个类这个类里有属性 +public class Students{ + public string Name{get;set;}=null!; + public string Age{get;set;}=null!; + public string Weight{get;set;}=null!; + public string Height{get;set;}=null!; +} +- 第三部,因该方法在浏览器中无法查看,需到Postman这个软件中查看结果 + +3. 因第二个方法无法在浏览器中查看,则需在控制器中方法(公共)中构造一个新的对象,将要显示的信息放在其中(可在页面显示),在将信息传给视图 + public IActionResult Index(){ + var students=new Students{ + Name="零零", + Age="33", + Weight="55", + Height="34" + }; + return View(students); + } \ No newline at end of file -- Gitee