我已经部署了一个从identityserver4快速入门(https://github.com/IdentityServer/IdentityServer4.Demo)构建的项目。只要我在本地运行它,它就能正常工作,但当我将它部署到Azure时,索引页面会返回404,但当我手动转到其他路径(如"/account/login")时,它们会按预期工作。
我的Startup.cs:
using System;
using System.Linq;
using System.Threading.Tasks;
using LunchBucks.Auth.Extensions;
using LunchBucksEncryption;
using LunchBucksEncryption.PasswordHashing;
using LunchBucksEncryption.SaltGeneration;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
namespace LunchBucks.Auth
{
public class Startup
{
// 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.AddTransient<ISaltGeneration, SaltGeneration>();
services.AddTransient<IPasswordHashing, PasswordHashing>();
services.AddTransient<IEncryptionManagement, EncryptionManagement>();
services.AddMvc();
services.AddIdentityServer()
.AddDeveloperSigningCredential()
.AddInMemoryApiResources(ApiResourceExtensions.GetApiResources())
.AddInMemoryClients(ClientExtensions.GetClients())
.AddInMemoryIdentityResources(ClientExtensions.GetIdentityResources())
.AddLunchBucksUserStore();
services.AddCors(options =>
{
options.AddPolicy("default", policy =>
{
policy.WithOrigins("http://localhost:3000")
.AllowAnyHeader()
.AllowAnyMethod();
policy.WithOrigins("https://lunchbucks-frontend.azurewebsites.net")
.AllowAnyHeader()
.AllowAnyMethod();
});
});
}
// 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.UseCors("default");
app.UseIdentityServer();
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" });
});
}
}
}
Program.cs:
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
}
Azure Web App默认文档:
带有控制器和视图的整个MVC应用程序文件夹结构与快速入门完全相同。
我不知道这里出了什么问题,因为它在本地工作,所以任何帮助都将不胜感激:)提前感谢。
发布于 2018-12-19 01:02:26
我发现了问题所在--很简单,我只是没有注意到而已。当你出于某些原因下载快速入门时,这是在主页的控制器中:
很抱歉给您带来不便,感谢您的帮助:)
发布于 2018-12-18 04:05:25
这很可能是因为https重定向没有正确配置。问题是没有默认的https端口。快速解决方法是添加下面这一行:
services.AddHttpsRedirection(options => options.HttpsPort = 443);
有关更多信息,请阅读documentation。
https://stackoverflow.com/questions/53821889
复制相似问题