问题描述
我是 asp.net core 的新手,最近我一直在用这个框架创建新项目。
我的问题是我无法使用另一台机器的 IP 地址访问该应用程序。我在我的防火墙中创建了规则并在我的计算机中打开了 5001 端口,还在我的路由器设置中定义了 DMZ
当我使用 Apache Web 服务器处理来自互联网和局域网的请求时,请求被发送到我的计算机,但如果我使用 kestrel,我无法打开我的 web 应用程序的介绍页面 例如我的静态 IP 地址和端口是:123.234.456.567:5001 当我运行 apache web 服务器并在我的手机浏览器中输入这个地址时,我可以看到 xampp 的介绍页面 但是当我运行 kesterl 服务器时,页面没有加载
这是我在我的应用程序中的代码: 这是program.cs里面的代码:
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseKestrel();
webBuilder.UseContentRoot(Directory.GetCurrentDirectory());
webBuilder.UseIISIntegration();
webBuilder.UseUrls("http://*:5001");
webBuilder.ConfigureKestrel(options => { options.ListenAnyIP(5001);});
webBuilder.UseStartup<Startup>();
});
}
这是startup.cs里面的代码:
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app,IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios,see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
//app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
}
这里是launchSetting.json文件:
{
“iis设置”:{
"windowsAuthentication": false,"anonymousAuthentication": false,"iisExpress": {
"applicationUrl": "http://localhost:54405","sslPort": 0
}
},“个人资料”:{
"IIS Express": {
"commandName": "Project","launchbrowser": true,"environmentvariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},"ancmHostingModel": "InProcess"
},"Event_Creator": {
"commandName": "Project","dotnetRunMessages": "true","applicationUrl": "http://0.0.0.0:5001/"
}}}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)