J'ai une interface graphique lorsque je me connecte je crée un cookie et le crypte. Je suis usin SSL. Je vérifie sur la page Login.aspx si le cookie est sécurisé, ce qui est le cas. mais avant d'aller à la page par défaut, il va à la page Global.ascx.cookie par défaut non sécurisé mais sécurisé en SSL
Ici, dans le Application_AuthenticateRequest il obtient le cookie et déchiffre pour la page par défaut ..
Maintenant, je sais qu'il est d'obtenir le même cookie que tous les autres attributs correspondent à celui qui a été créé dans le Login. page aspx excet que la valeur sécurisée est "False".
c'est le cas pour toutes les autres pages après défaut. la valeur de cookie.secure est false.
S'il vous plaît aidez-moi pourquoi cela se passe que je veux que toutes les pages soient sécurisées par SSL.
Aussi les pages s'ouvrent comme https not http.
ici est mon web.config
<authentication mode="Forms">
<forms loginUrl="Login.aspx" defaultUrl="~/Default.aspx" name="copiunGUI" slidingExpiration="true" timeout="120" path="/" requireSSL="true" protection="All">
</forms>
</authentication>
<httpCookies requireSSL="true"/>
<authorization>
<deny users="?"/>
</authorization>
mon code global.aspx
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
// Extract the forms authentication cookie
string redirectSecureUrl = Request.Url.ToString();
new GUIUtility().LogMessageToFile(redirectSecureUrl);
string cookieName = FormsAuthentication.FormsCookieName.ToString();
HttpCookie authCookie = Context.Request.Cookies[cookieName];
try
{
new GUIUtility().LogMessageToFile(cookieName + authCookie.Secure + authCookie.Name + authCookie.Expires + authCookie.Path);
}
catch (Exception)
{
//
}
if (null == authCookie)
{
try
{
new GUIUtility().LogMessageToFile("authCookie = null");
}
catch (Exception)
{
//
}
// There is no authentication cookie.
return;
}
FormsAuthenticationTicket authTicket = null;
try
{
authTicket = FormsAuthentication.Decrypt(authCookie.Value);
}
catch (Exception)
{
// Log exception details (omitted for simplicity)
return;
}
if (null == authTicket)
{
// Cookie failed to decrypt.
return;
}
// When the ticket was created, the UserData property was assigned a
// pipe delimited string of role names.
string[] roles = authTicket.UserData.Split(new char[] { '|' });
// Create an Identity object
FormsIdentity id = new FormsIdentity(authTicket);
// This principal will flow throughout the request.
GenericPrincipal principal = new GenericPrincipal(id, roles);
// Attach the new principal object to the current HttpContext object
Context.User = principal;
}
Code
dans ma page login.aspx
// Create the authentication ticket
FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, // version
UserName.Text, // user name
DateTime.Now, // creation
DateTime.Now.AddMinutes(60),// Expiration
false, // Persistent
role); // User data
// Now encrypt the ticket.
string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
// Create a cookie and add the encrypted ticket to the
// cookie as data.
HttpCookie authCookie =
new HttpCookie(FormsAuthentication.FormsCookieName,
encryptedTicket);
if (authCookie.Secure)
{
new GUIUtility().LogMessageToFile("The cookie is secure with SSL." + authCookie.Name + authCookie.Expires + authCookie.Path);
}
//authCookie.Secure = FormsAuthentication.RequireSSL;
// Add the cookie to the outgoing cookies collection.
HttpContext.Current.Response.Cookies.Add(authCookie);
// Redirect the user to the originally requested page
string goToPath = FormsAuthentication.GetRedirectUrl(UserName.Text, true);
new GUIUtility().LogMessageToFile(goToPath);
//here the value of gotoPath is /Default.aspx
Response.Redirect(FormsAuthentication.GetRedirectUrl(UserName.Text,false));
donc dans la page de connexion j'ai la fonction "string goToPath = FormsAuthentication.GetRedirectUrl (UserName.Text, true);" la valeur est /Default.aspx qui est un chemin absolu ... puis je le redirige .. où il va à la page global.ascx où je vérifie d'abord l'URL par "string redirectSecureUrl = Request.Url.ToString();" la valeur ici est "https: //Default.aspx" .. donc je n'arrive pas à comprendre pourquoi le cookie passe de sécurisé à la connexion à non sécurisé sur global.aspx ... aucune suggestion .. merci – user175084