我目前正在使用EpiServer CMS 8工作并使用Owin / ASP.Net Identity替换登录。
在本地IIS上一切正常,但在部署到我们的测试服务器时,导航到/ episerver /不会重定向到登录页面,但会直接提供401.2未经授权的结果。
以下是我的启动课程
[assembly: OwinStartup(typeof(Website.Startup))]
namespace Website
{
public class Startup
{
private const string PathRoot = "~/";
private const string LogoutUrl = "/Account/Logout";
private const string LoginUrl = "/Account/Login";
private const string BackendLoginUrl = "~/BackendAccount/";
private const string BackendLogoutUrl = "~/Util/Logout.aspx";
public void ConfigureAuth(IAppBuilder app)
{
Configuration(app);
}
public void Configuration(IAppBuilder app)
{
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString(VirtualPathUtility.ToAbsolute(LoginUrl)),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager)),
OnApplyRedirect = ApplyRedirect
}
}, PipelineStage.Authenticate);
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
app.Map(VirtualPathUtility.ToAbsolute(LogoutUrl), map =>
{
map.Run(ctx =>
{
ctx.Authentication.SignOut();
return Task.Run(() => ctx.Response.Redirect(VirtualPathUtility.ToAbsolute(PathRoot)));
});
});
app.Map(VirtualPathUtility.ToAbsolute(BackendLogoutUrl), map =>
{
map.Run(ctx =>
{
ctx.Authentication.SignOut();
return Task.Run(() => ctx.Response.Redirect(VirtualPathUtility.ToAbsolute(PathRoot)));
});
});
app.UseStageMarker(PipelineStage.MapHandler);
}
private static void ApplyRedirect(CookieApplyRedirectContext context)
{
string backendPath = Paths.ProtectedRootPath.TrimEnd('/');
if (context.Request.Uri.AbsolutePath.StartsWith(backendPath, StringComparison.CurrentCultureIgnoreCase) && !context.Request.User.Identity.IsAuthenticated)
{
context.RedirectUri = VirtualPathUtility.ToAbsolute(BackendLoginUrl) +
new QueryString(
context.Options.ReturnUrlParameter,
context.Request.Uri.AbsoluteUri);
}
context.Response.Redirect(context.RedirectUri);
}
}
}
我的web.config包含以下部分
<authentication mode="None">
</authentication>
<membership defaultProvider="OwinMembershipProvider" userIsOnlineTimeWindow="10" hashAlgorithmType="HMACSHA512">
<providers>
<clear /
<add name="OwinMembershipProvider"
type="Website.Shared.Providers.OwinMembershipProvider"
enablePasswordRetrival="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="false"
passwordFormat="Hashed"
passwordStrengthRegularExpression=""
minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="0"
connectionString="TestConnection"
/>
</providers>
</membership>
<roleManager enabled="true" defaultProvider="OwinRoleProvider" cacheRolesInCookie="true">
<providers>
<clear />
<add name="OwinRoleProvider" type="Website.Shared.Providers.OwinRoleProvider"/>
</providers>
</roleManager>
我尝试比较服务器之间的iis设置,但我发现没有区别。我真的不知道如何解决这个问题,我已经尝试了Owin guide for startup handling上列出的所有内容。 OwinMembershipProvder和OwinRoleProvider基于http://www.mogul.com/om-mogul/blogg/owin-membership-and-role-provider-for-episerver的代码,但经过扩展和修改以符合我们的要求
答案 0 :(得分:1)
通过首先清除ASP.Net临时文件来解决这个问题 将web.config设置为
重新启动站点<add key="owin:AutomaticAppStartup" value="true" />
<add key="owin:AppStartup" value="Website.Startup" />
我之前曾测试过这两个值的每种可能组合都没有成功。
我不能肯定地说,但清除缓存和从AppStartup密钥中删除程序集名称的组合可能就是解决方案。