当前位置:网站首页>ASP.NET Core 使用记录1
ASP.NET Core 使用记录1
2022-07-20 07:39:00 【人类群星闪耀时】
ASP.NET 项目启动 提示 ID为XXX的进程未启动
原因:暂时不能明确。
解决方案:
删除项目的 csproj 文件的WebProjectProperties节点内容。
<WebProjectProperties>
<UseIIS>True</UseIIS>
<AutoAssignPort>True</AutoAssignPort>
<DevelopmentServerPort>0</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl>http://localhost:55990/</IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>False</UseCustomServer>
<CustomServerUrl>
</CustomServerUrl>
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
</WebProjectProperties>
ASP.NET CORE 监听地址
在将项目部署到云服务器上时,在云服务器启动项目服务时,默认的 launchsetting.json 里的applicationUrl是监听 http://localhost:5000 这些url,而我们要想通过公网访问我们的接口服务,这样的配置是不行的。
需要改成 http://*:5000 这样的url,才能通过公网IP来访问我们的项目服务。
ASP.NET Core 设置urls
其中设置url的优先级问题:Kestrel > 命令行 > 配置文件 > UseUrls > 环境变量 > 默认值
- kestrel 配置
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
// 配置Kestrel服务
webBuilder.UseKestrel(kestrelServerOptions =>
{
kestrelServerOptions.ListenLocalhost(7004);
kestrelServerOptions.ListenLocalhost(7014, listenOptions => listenOptions.UseHttps());
});
});
- 命令行配置
dotnet AspNetCoreUrl.dll --urls "http://localhost:7001;https://localhost:7011"
- 配置文件
在生成程序的根目录下,打开appsettings.json文件,添加url配置项
{
"urls":"http://localhost:7002;http://localhost:7012"
}
- useurls 配置
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
// 使用UseUrls设置监听的端口和协议
webBuilder.UseUrls("http://localhost:7003", "https://localhost:7013");
});
- 环境变量配置
在不修改AspNetCoreUrl任何源代码的情况下(即创建项目时的程序默认状态)生成程序,定位到生成的根目录下,打开命令行终端
# 环境变量仅在当前命令行窗口生效
$Env:ASPNETCORE_URLS = "http://localhost:7000;https://localhost:7010"
# 或者使用DOTNET_URLS环境变量同样可生效
$Env:DOTNET_URLS = "http://localhost:8000;https://localhost:8010"
# 运行AspNetCoreUrl程序
dotnet AspNetCoreUrl.dll
如果使用Windows命令行(即cmd命令行),使用下面的方式设置
# 环境变量仅在当前命令行窗口生效
set ASPNETCORE_URLS=http://localhost:7000;https://localhost:7010
# 将ASPNETCORE_URLS变量保存到用户环境变量中
setx ASPNETCORE_URLS "http://localhost:7000;https://localhost:7010"
# 加/m参数,将ASPNETCORE_URLS变量保存到系统环境变量中
setx ASPNETCORE_URLS "http://localhost:7000;https://localhost:7010" /m
# 运行AspNetCoreUrl程序
dotnet AspNetCoreUrl.dll
注意:使用setx设置环境变量后,需要打开新的Windows命令行窗口才会使用环境变量生效
在Linux系统中使用以下命令设置环境变量
# 环境变量仅在当前终端生效,关闭终端后需要重新设置
export ASPNETCORE_URLS="http://localhost:7000;https://localhost:7010"
- 默认值
默认值就是默认监听的 5000 和 5001端口号.
边栏推荐
- pypi 统计下载次数
- Okaleido或杀出NFT重围,你看好它吗?
- 创建K26 SOM最小系统
- 小程序毕设作品之微信运动场地预约小程序毕业设计(8)毕业设计论文模板
- 【深入浅出玩转FPGA9------经验点滴】
- [Verilog digital system design (Xia Yuwen) -- basic knowledge of Verilog 2]
- SQLite memory mode save
- 1.54寸TFT ST7789液晶屏图片如何取模
- [binary tree] rebuild the binary tree (find the root first, divide and conquer in the middle)
- 2022年第二季度 Web3 成为加密风投最感兴趣的领域
猜你喜欢
Don't use the line segment tree to solve all my schedule problems with one idea
02 requsets请求库
【深入浅出玩转FPGA9------经验点滴】
03 beautifulsoup parsing library
不用线段树,一个思路解决所有我的日程安排表问题
Mysql 常用函数汇总,很实用,面试时常会遇到
PO,BO,VO,DTO和POJO的概念区分
Daily question 1: specified interval reversal in the linked list
Program environment and pretreatment
Run Keyword If 使用详解
随机推荐
Filebeat 的学习笔记
Force buckle 741 Cherry picking
postgreSQL里怎么切换结束符?
Lua脚本语言入门
MySQL的增删查改【进阶】
利用哈希来解决问题
AutoJs學習-投幣小遊戲
Pango debug grab signal
Unicode encoding output 12 zodiac emoticons
Jmeter 接口必加元素
MySQL JDBC programming
每日三题 7.15
两种常见的Vlan间通信的方式
[in simple terms, play with fpga9 ----- experience drops]
Swift reads the bundle file
C reflection and factory mode
Jenkins插件开发——插件的拓展
Openresty缓存使用
list.stream常用操作
Redis实现秒杀系统