当使用WebHostBuilder在一个Main入口点,我怎么可以指定它绑定到端口?
默认情况下,它使用5000.
请注意,此问题特定于新的ASP.NET Core API(当前位于1.0.0-RC2中).
我想从AWS Amazon Linux AMI实例运行.NET Core MVC网站.
以下是我到目前为止采取的步骤:
sudo yum update -ysudo yum install libunwind -ysudo yum install gettext -ycurl -sSL https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0-preview1/scripts/obtain/dotnet-install.sh | bash /dev/stdin --version 1.0.0-preview1-002702 --install-dir ~/dotnetsudo ln -s ~/dotnet/dotnet /usr/local/bincurl -sSL https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.sh | DNX_BRANCH=dev sh && source ~/.dnx/dnvm/dnvm.shsource /home/ec2-user/.dnx/dnvm/dnvm.sh我有以下入口点:
public static void Main(string[] args)
{
var config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("hosting.json", optional: true)
.AddCommandLine(args)
.AddEnvironmentVariables()
.Build();
var host = new WebHostBuilder()
.UseConfiguration(config)
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
}
Run Code Online (Sandbox Code Playgroud)
如果我添加hosting.json文件,例如
{
"server.urls": "http://0.0.0.0:5001"
}
Run Code Online (Sandbox Code Playgroud)
或者如果我定义环境变量(在这里找到名称)
SET ASPNETCORE_URLS=https://0.0.0.0:5001
Run Code Online (Sandbox Code Playgroud)
但是,如果我--server.urls http://0.0.0.0:5001作为参数传递,则应用程序将监听默认的5000端口:
> dotnet run --server.urls http://0.0.0.0:5001
...
Now listening on: http://localhost:5000
Run Code Online (Sandbox Code Playgroud) 我想连接到我的Kestrel服务器,其中托管的ASP.NET 5应用程序来自同一网络中的另一台PC.可能吗?我可以从cmd ping我的电脑,但当我尝试从网络浏览器连接时,我得到'连接超时'(我输入:"http:// {my_kestrel_ip}:5000 /").
我成功使用ASP.NET Core设置了IdentityServer4。
作为默认配置,我有这个:
IdentityServerAuthenticationOptions options = new IdentityServerAuthenticationOptions()
{
Authority = "http://localhost:5000",
ScopeName = "scope",
ScopeSecret = "ScopeSecret",
AutomaticAuthenticate = true,
AutomaticChallenge = true,
RequireHttpsMetadata = false,
};
Run Code Online (Sandbox Code Playgroud)
现在,使用本指南,我配置为从配置文件中读取数据,因此它们可以是生产中的任何数字。
例如,如果我将API设置为在上运行,http://*:5000则客户端可以通过服务IP地址(例如)连接到它http://192.168.1.100:5000。
一旦客户端获得Bearer令牌并尝试使用它,Internal Server Error就会发生此异常:
Unable to obtain configuration from:
'http://*:5000/.well-known/openid-configuration'.
---> System.IO.IOException: IDX10804: Unable to retrieve document from: 'http://*:5000/.well-known/openid-configuration'.
---> System.UriFormatException: Invalid URI: The hostname could not be parsed.
Run Code Online (Sandbox Code Playgroud)
将IdS4配置为具有动态权限的正确方法是什么?
更新资料
看来问题出在发行人身上,对此有什么想法吗?
Microsoft.IdentityModel.Tokens.SecurityTokenInvalidIssuerException:
IDX10205: Issuer validation failed. Issuer: 'http://192.168.1.100:5000'. Did not match: validationParameters.ValidIssuer: …Run Code Online (Sandbox Code Playgroud)