Wprowadziłem schemat wyzwania-odpowiedzi jako program obsługi Ajax. Z jakiegoś powodu przestał działać po kilku miesiącach pracy. Badanie problemu wykazało, że Context.Session[KEY]
stracił wartość między wezwaniem a wezwaniami.Sesja IIS7 traci swoje wartości
kładę Session_Start
i Session_End
(i kilka innych) metod w Global.asax.cs z jakiś rejestrowania i widzę nowe wydarzenie session_start wyrzuceniu z tej samej sesji ID i nie było żadne zdarzenie Session_End
Pytanie brzmi: dlaczego usługi IIS tracą wartości sesji?
Aktualizacja: Próbowałem przejść do sesji SQLServer, ale nie było zmian w zachowaniu. W rzadkich przypadkach sesje działają zgodnie z przeznaczeniem, nie wiem dlaczego. Wypróbowałem wszystkie instrukcje "rozwiązywania problemów z utratą sesji", które mogłem znaleźć bez żadnego skutku.
AKTUALIZACJA 2: Zawęziłem problem do brakującego pliku cookie sesji, ale modyfikacja konfiguracji my.browsers nie rozwiązała problemu po kilku próbach. Kiedy wołam obsługę ajax z przeglądarki, plik cookie sesji "ASP.NetSessionId" pojawia się zgodnie z oczekiwaniami. Zmieniłem nazwę pliku cookie w ustawieniach IIS zarówno dla witryny, jak i serwera na "SessionId", ale nadal widziałem ASP.NET, nawet po zrestartowaniu serwera. Nadal chciałbym przekazać nagrodę komuś, kto ma pojęcie o tym, co się dzieje. W międzyczasie rozwiązałem ten problem, ustawiając plik cookie sesji w kodzie.
Pseudo kod do Login.ashx:
string login = GetParameter("login", context);
string passhash = GetParameter("pass", context);
string challenge = "" + Context.Session["CHALLENGE"];
if (!string.IsNullOrEmpty(challenge))
{
// this is the 'response' part
string challengeResponse = Crypto.GetChallengeResponse(Challenge, UserFromDB.PassHash);
if (challengeResponse == passhash)
{
// Great success, challenge matches the response
Log.I("Success");
return "SUCCESS";
}
else
{
Log.W("Failed to respond");
return "FAILED TO RESPOND";
}
}
else
{
// if passed login or session-stored challenge are empty - issue a new challenge
challenge = "Challenge: "+ Crypto.GetRandomToken();
Context.Session["CHALLENGE"] = challenge;
Log.I("Sent Challenge"); // this is what's in the log below
return challenge;
}
Oto dziennik, Sesja rozpoczęła pojawia się z każdej rozmowy, Session.Keys.Count pozostaje 0 mimo Session [ "wyzwanie"] powinien być ustawiony:
// This is the challenge request:
[] **Session started**: sr4m4o11tckwc21kjryxp22i Keys: 0 AppDomain: /LM/W3SVC/1/ROOT-4-130081332618313933 #44
[] Processing: <sv> **MYWEBSITE/ajax/Login.ashx** SID=sr4m4o11tckwc21kjryxp22i
[] Sent Challenge @Login.ashx.cs-80
// this is the response, note that there's another Session started with the same id
// and the session didn't keep the value ["CHALLENGE"], there are no session-end events either
[] **Session started**: sr4m4o11tckwc21kjryxp22i Keys: 0 AppDomain: /LM/W3SVC/1/ROOT-4-130081332625333945 #93
[] Processing: <sv> **MYWEBSITE/ajax/Login.ashx?login=MYLOGIN&pass=RuhQr1vjKg_CDFw3JoSYTsiW0V0L9K6k6==**
[] Sent Challenge @Login.ashx.cs-80 >Session: sr4m4o11tckwc21kjryxp22i
web config, odkażane
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<appSettings>
<add key="IncludeStackTraceInErrors" value="false" />
</appSettings>
<connectionStrings>
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
<add name="MYConnection" connectionString="metadata=res://*…. and a bunch of other stuff that works" providerName="System.Data.EntityClient" />
</connectionStrings>
<system.web>
<compilation targetFramework="4.5">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx" timeout="2880" />
</authentication>
<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
</providers>
</membership>
<profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
</providers>
</profile>
<roleManager enabled="false">
<providers>
<clear/>
<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
</providers>
</roleManager>
<pages controlRenderingCompatibilityVersion="4.0" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
</entityFramework>
</configuration>
możemy zobaczyć swoje ustawienia web.config – Element
@Element dodane do postu –
Have sprawdziłeś żądanie/odpowiedź w narzędziu do debugowania przeglądarki, takim jak Firebug?Wszelkie [nieprawidłowe źródła obrazów] (http://stackoverflow.com/questions/12623691/session-variable-value-changes-between-page-processing-somehow?rq=1)? – Sumo