ASP.NET CORE 2.0 localhost拒绝在mac上连接但在Windows

时间:2018-02-01 15:26:59

标签: c# asp.net macos asp.net-core

我一直在使用ASP.NET Core 2.0开发Web应用程序。该解决方案最初是在Windows机器上创建的,并且工作正常。当我尝试在我的Mac上启动它时,它会启动,当它在Chrome上打开网站时,它说localhost拒绝连接。我已经没有想法,也没有在网上找到任何有用的东西。

我感觉它与SSL有关。在VS中,它显示Now listening on: http://localhost:51684,但浏览器会打开网址https://localhost/。没有港口或任何东西。当我粘贴http://localhost:51684时,它会再次转发到https://localhost/

我的launchsettings.json文件包含以下内容

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "https://localhost:44314/",
      "sslPort": 44314
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "TestApp": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "http://localhost:51684/"
    }
  }
}

当我尝试访问iisSettings https://localhost:44314/中列出的URL时,我得到了相同的localhost拒绝连接消息。

这是我的Startup.cs文件中的内容

public class Startup
{

    private IConfiguration _configuration;

    public Startup(IConfiguration configuration)
    {
        _configuration = configuration;
    }

    // This method gets called by the runtime. Use this method to add services to the container.
    // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddDbContext<TestDbContext>(
            options => options.UseMySql(_configuration.GetConnectionString("MySqlConnection")));
        services.AddIdentity<User, IdentityRole>().AddEntityFrameworkStores<TestDbContext>();
        services.Configure<MvcOptions>(options =>
        {
            options.Filters.Add(new RequireHttpsAttribute());
        });
        services.AddScoped<IUserDAL, UserDAL>();
        services.AddScoped<ITestDataDAL, TestDataDAL>();
        services.AddMvc().AddSessionStateTempDataProvider();

        services.AddMemoryCache();
        services.AddSession();
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        app.UseRewriter(new RewriteOptions().AddRedirectToHttpsPermanent());
        app.UseStaticFiles();
        app.UseAuthentication();
        app.UseSession();
        app.UseMvc(ConfigureRoutes);
    }

    private void ConfigureRoutes(IRouteBuilder routeBuilder)
    {
        routeBuilder.MapRoute("Default",
            "{controller=User}/{action=Register}/{id?}");
    }
}

我对ASP.NET Core不太熟悉,我想不出任何解决方案。非常感谢任何帮助!

0 个答案:

没有答案