【发布时间】:2020-08-31 15:35:42
【问题描述】:
Web 部署发布到远程 IIS 后,ASP.NET Core 3.1 身份持久化 cookie 身份验证仍然失败
我正在使用这个答案的解决方案 https://stackoverflow.com/a/56493862/3650307
public Startup(IConfiguration configuration, IHostingEnvironment environment) {
Configuration = configuration;
hostingEnvironment = environment;
}
private IHostingEnvironment hostingEnvironment;
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) {
// create a directory for keys if it doesn't exist
// it'll be created in the root, beside the wwwroot directory
var keysDirectoryName = "Keys";
var keysDirectoryPath = Path.Combine(hostingEnvironment.ContentRootPath, keysDirectoryName);
if (!Directory.Exists(keysDirectoryPath)) {
Directory.CreateDirectory(keysDirectoryPath);
}
services.AddDataProtection()
.PersistKeysToFileSystem(new DirectoryInfo(keysDirectoryPath))
.SetApplicationName("CustomCookieAuthentication");
services.Configure<CookiePolicyOptions>(options =>
{
...
我做了很多谷歌搜索和研究(如果这也与 asp.net core 3.1 https://stackoverflow.com/a/3516058/3650307 有关)
我正在部署到基于俄罗斯的网络托管 REG.RU,在 IIS Web 部署发布后我的 cookie 仍然不存在,每次重新部署后我都必须重新登录。
我不明白社区会建议我广泛检查我的远程服务器托管日志,但至少可以帮助我在远程 Windows Web asp.net 应用程序托管提供商(通常是 REG .ru 托管使用 Plesk 管理面板,但我知道日志记录可能在 web.config 或其他 ASP.NET 应用程序文件夹文件管理器中启用)
在将 IIS Web 部署发布到 ASP.NET Windows 主机时,是否有其他人最近遇到过持久 cookie 登录 asp.net core 3.1 身份的问题?
在发布过程中重写 web.config 文件可能会影响应用程序的重新启动,因此即使考虑存储密钥,cookie 也不再起作用?如果是,有没有办法防止 web.config 重写?
是的,当我检查 xml 密钥文件时,密钥文件夹出现在 FTP 上
【问题讨论】:
-
一位开发人员提示我,我想在发布配置文件选项中取消选中“在目标位置删除其他文件”。这既是天才,又是简单明了的。但是,现在我试图了解未选中的“在目标位置删除其他文件”如何影响我的 pulish 生命周期,因为当我更新从未构建的应用程序时,例如我希望删除一些文件,例如静态 img 和 js 内容,我可以必须通过 ftp 手动删除它们,并在发布更新生命周期期间取消选中删除附加文件选项
标签: c# asp.net iis cookies asp.net-identity