微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何远程访问 Asp.net core Mvc 5 中的 Kestrel?

如何解决如何远程访问 Asp.net core Mvc 5 中的 Kestrel?

我是 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 举报,一经查实,本站将立刻删除。