쿠키 권한을 사용하여 MVC 사이트에서 WebApi로 Ajax 요청을 만들고 싶습니다. BUT 문제가 생겼습니다.도메인 간 쿠키 인증 문제 WebApi ASP.NET
ControllerContext.RequestContext.Principal
가 null입니다. 그것은 요청에 존재하지 않는 한 그것은 쿠키를 인식 할 수없는 것 같습니다. 두 응용 프로그램이 있습니다 1 - MVC 주 2 - WebApi 추가 MVC는 WebApi를 요청합니다. 둘 다 공통 신원 사용자를 사용합니다. 여기
내 구현 IAppBuilderpublic static void Register(IAppBuilder app)
{
app.CreatePerOwinContext(MyDbContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
CookieName = ".AspNet.Cookies",
CookieSecure = CookieSecureOption.Never,
AuthenticationMode = AuthenticationMode.Active
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
}
내하게, ApplicationManager에 대한
등록입니다 :
WebApi 및 MVC에서public class ApplicationUserManager : UserManager<ApplicationUser> { public ApplicationUserManager(IUserStore<ApplicationUser> store) : base(store) { } public static ApplicationUserManager Create(IdentityFactoryOptions<ApplicationUserManager> options, IOwinContext context) { var appDbContext = context.Get<MyDbContext>(); var appUserManager = new ApplicationUserManager(new UserStore<ApplicationUser>(appDbContext)); return appUserManager; } }
같은 machineKeys
< machineKey 복호 = "AES"및 decryptionKey = "F7F ..." 검증 = "SHA1"validationKey의 = "DD2 ..."/ >
권한 부여 덮여 컨트롤러
[Authorize] [EnableCors(origins: "*", headers: "*", methods: "*", SupportsCredentials = true)] public sealed class BalanceController : ApiController ...
속성
도움주세요.