Çerezleri paylaşabilmem için aşağıda belirtilen ana ana etki alanını paylaşan 2 web uygulamasına sahibim. Her iki projede de Web.conifg aynı makine anahtarı ve doğrulama anahtarına sahiptir. Kimlik ve NOT formları kimlik doğrulaması kullanmak istediğim için web.config dosyamdan birinde bir düğüm yok. SSO'dan Auth çerezini başarılı bir şekilde oluşturabiliyorum ve SSO'daki yetkili sayfaları görüntüleyebiliyorum ancak MVC projesinde yetkili bir görünüme erişmeye çalıştığımda SSO oturumuna yeniden yönlendiriliyorum.Tek Oturum Açma 2 ASP.NET MVC projeleri arasında ASP.NET Kimliği'ni kullanma
- sso.domain.com - MVC Proje
- mvc.domain.com - MVC Proje
aşağıda gibi benim TOA ve MVC projesinde bir startup.cs dosyası var:
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
}
// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
public void ConfigureAuth(IAppBuilder app)
{
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
// Enable the application to use a cookie to store information for the signed in user
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
ExpireTimeSpan = TimeSpan.FromMinutes(3),
LoginPath = new PathString("/Login"),
CookieName = "MyCookieName",
CookieDomain = ".domain.com"
});
app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);
AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimTypes.NameIdentifier;
}
}
Aşağıda, SSCo projesinde AccountController.cs altında bulunan kod yer almaktadır. Ben çerez oluşturur veritabanına karşı kullanıcıyı doğrulamak aşağıda IdentitySignin işlevini çağırır:
private void IdentitySignin(string userId, string name, string providerKey = null, bool isPersistent = false)
{
var claims = new List<Claim>();
// create *required* claims
claims.Add(new Claim(ClaimTypes.NameIdentifier, userId));
claims.Add(new Claim(ClaimTypes.Name, name));
var identity = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);
//get the expiry minutes from config or use the default value of 30 minutes
double expiryMinutes;
expiryMinutes = double.TryParse(ConfigurationManager.AppSettings["AuthCookieExpiryMinutes"], out expiryMinutes) ? expiryMinutes : 30;
// add to user here!
AuthenticationManager.SignIn(new AuthenticationProperties()
{
AllowRefresh = true,
IsPersistent = isPersistent,
ExpiresUtc = DateTime.UtcNow.AddMinutes(expiryMinutes),
IssuedUtc = DateTime.UtcNow
}, identity);
}
private void IdentitySignout()
{
AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie, DefaultAuthenticationTypes.ExternalCookie);
}
private IAuthenticationManager AuthenticationManager
{
get
{
return HttpContext.GetOwinContext().Authentication;
}
}
private async Task<string> GetVerifiedUserIdAsync()
{
var result = await AuthenticationManager.AuthenticateAsync(
DefaultAuthenticationTypes.ApplicationCookie);
if (result != null && result.Identity != null
&& !String.IsNullOrEmpty(result.Identity.GetUserId()))
{
return result.Identity.GetUserId();
}
return null;
}
Bu Chris hakkındaki hızlı yanıt için teşekkürler, ancak yukarıdaki soruda belirtmiş olduğum gibi, her iki projenin web.config dosyasında da aynı makine anahtarı yapılandırmasına sahibim. – user2272865