【问题标题】:You do not have permission to view this directory or page. Azure您无权查看此目录或页面。天蓝色
【发布时间】:2018-09-14 12:30:56
【问题描述】:

我正在使用 .net Core,当我部署我的代码时,我收到了消息 “您无权查看此目录或页面。”在我的 Azure 应用服务 URL 上。 在部署之前,我没有收到此错误。

我的问题是,当我尝试用谷歌搜索这个错误时,我不断得到结果,我必须在我的 web.config 中进行一些调整,但 .net Core 没有文件。 部署程序并使用 localhost 可以使 api 调用正常工作。

这里的其他人在使用 .net Core 时遇到了同样的问题,并找出了问题所在???

这是我的 Startup.cs 文件

public class Startup
{
    public IConfigurationRoot Configuration {get; set;}
    public static string ConnectionString {get; set;}        

    // public Startup(IConfiguration configuration)
    // {
    //     Configuration = configuration;
    // }

    public Startup(IHostingEnvironment env){
        Configuration = new ConfigurationBuilder()
                            .SetBasePath(env.ContentRootPath)
                            .AddJsonFile("appsettings.json")
                            .Build();
    }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
    }

    // 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();
        }
        else
        {
            app.UseHsts();
        }

        app.UseHttpsRedirection();
        app.UseMvc();

        ConnectionString = Configuration["ConnectionStrings:TestingConnection"];
    }
}

【问题讨论】:

  • 您必须分享一些代码,以便我们能够提供帮助。
  • 您想查看哪个文件?启动.cs ???
  • 这将是一个好的开始。
  • 尝试将这些添加到您的 Configure 方法中:app.UseDefaultFiles(); app.UseMvcWithDefaultRoute(); app.UseStaticFiles();

标签: azure asp.net-core


【解决方案1】:

“您无权查看此目录或页面。”

我假设你没有default document。如果是这种情况,则应采取行动。

您将 Web 应用程序项目发布到 azure,默认页面将正确显示。在您的情况下,如果它在本地工作,您可以直接测试 azure Rest API。

默认文档是显示在网站根 URL 处的网页。使用列表中的第一个匹配文件。 Web 应用程序可能使用基于 URL 路由的模块,而不是提供静态内容,在这种情况下,没有这样的默认文档。

【讨论】:

    【解决方案2】:

    我们发现使用命令行发布到 azure 完全没有问题,因此我们的 API 服务现已启动并运行。

    出于某种原因,我们无法使用我们在 Visual Studio 代码中安装的 Azure 插件来完成此操作

    【讨论】:

      猜你喜欢
      • 2016-10-31
      • 1970-01-01
      • 1970-01-01
      • 2014-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-02
      • 2021-01-29
      相关资源
      最近更新 更多