alf*_*aur 5 asp.net asp.net-mvc amazon-web-services amazon-elb
我正在尝试将使用单个用户帐户的 ASP.NET MVC Web 应用程序部署到使用弹性负载均衡器 (ELB) 的 AWS 服务器。我已将该站点部署到 AWS 应用程序服务器上的 IIS,并将其连接到我的 AWS SQL 服务器,并且它在服务器上按预期工作(事实上,当我在 Visual Studio 中运行它或部署到内部服务器时)。
当远程访问它时就会出现问题,这当然是通过 ELB 进行的。
所以基本上,如果我登录了,那就没问题了。如果我没有登录,登录页面很好,但其他都没有。我和我们内部团队中一位与 AWS 合作的同事(顺便说一句,我问过他,他无法帮助我!)的想法是,当我被重定向到登录页面时,这是一个 HTTP 请求,而不是 HTTPS ,这就是问题的原因,但无论我尝试什么,我都无法让它使用 HTTPS 进行重定向。我试过了:
显然我的解决方法是让每个人都进入登录页面并从那里开始,而不仅仅是根 URL,但我真的很想对此进行排序,就好像重定向在这里不起作用一样,我可以看到它在其他地方不起作用并且可能导致问题。
按要求更新:我实际上对我的 ELB 没有任何控制权,因为这是由不同的团队完成的,但我从与团队交谈中了解到,它接受 HTTPS 流量,然后将其作为 HTTP 传递到服务器。
您的 MVC 应用程序配置为当用户需要登录时重定向到绝对 http URL,而不是相对 URL。
对于基于 Owin 中间件的新 MVC 应用程序,这是在App_Start/Startup.Auth.cs.
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
// Enables the application to validate the security stamp when the user logs in.
// This is a security feature which is used when you change a password or add an external login to your account.
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});
Run Code Online (Sandbox Code Playgroud)
并在属性后添加以下内容OnValidateIdentity:
OnApplyRedirect = ApplyRedirect
Run Code Online (Sandbox Code Playgroud)
然后,稍后在课程中添加以下函数:
private static void ApplyRedirect(CookieApplyRedirectContext context)
{
Uri absoluteUri;
if (Uri.TryCreate(context.RedirectUri, UriKind.Absolute, out absoluteUri))
{
context.Response.Redirect(absoluteUri.PathAndQuery);
return;
}
context.Response.Redirect(context.RedirectUri);
}
Run Code Online (Sandbox Code Playgroud)
基本上,这是将绝对 URL 转换为相对 URL。然后相对 URL 被传回浏览器。由于重定向是相对的,因此它应该保留 https URL。
| 归档时间: |
|
| 查看次数: |
1718 次 |
| 最近记录: |