【发布时间】: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