首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >将IdentityServer4快速入门部署到Azure Web应用程序在索引页面上返回404,但其他路径有效

将IdentityServer4快速入门部署到Azure Web应用程序在索引页面上返回404,但其他路径有效
EN

Stack Overflow用户
提问于 2018-12-18 03:33:32
回答 2查看 1.5K关注 0票数 5

我已经部署了一个从identityserver4快速入门(https://github.com/IdentityServer/IdentityServer4.Demo)构建的项目。只要我在本地运行它,它就能正常工作,但当我将它部署到Azure时,索引页面会返回404,但当我手动转到其他路径(如"/account/login")时,它们会按预期工作。

我的Startup.cs:

代码语言:javascript
运行
复制
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:

代码语言:javascript
运行
复制
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应用程序文件夹结构与快速入门完全相同。

我不知道这里出了什么问题,因为它在本地工作,所以任何帮助都将不胜感激:)提前感谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-12-19 01:02:26

我发现了问题所在--很简单,我只是没有注意到而已。当你出于某些原因下载快速入门时,这是在主页的控制器中:

很抱歉给您带来不便,感谢您的帮助:)

票数 9
EN

Stack Overflow用户

发布于 2018-12-18 04:05:25

这很可能是因为https重定向没有正确配置。问题是没有默认的https端口。快速解决方法是添加下面这一行:

代码语言:javascript
运行
复制
services.AddHttpsRedirection(options => options.HttpsPort = 443);

有关更多信息,请阅读documentation

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53821889

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档