HttpContext.Aktualne.Session is null when routing requests
BEZ routingu, {[2] } jest tam, więc wiem, że StateServer
działa. Kiedy Przekierowuję moje żądania, HttpContext.Current.Session
znajduje się null
na przekierowanej stronie. Używam. NET 3.5 sp1 na IIS 7.0, bez podglądu MVC. Wygląda na to, że AcquireRequestState
nigdy nie jest wywoływana podczas korzystania z tras, więc zmienna sesji nie jest tworzona/wypełniana.
Kiedy próbuję uzyskać dostęp do zmiennych sesji, pojawia się błąd:
base {System.Runtime.InteropServices.ExternalException} = {"Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive. Please also make sure that System.Web.SessionStateModule or a custom session state module is included in the <configuration>.
Podczas debugowania dostaję również błąd, że HttpContext.Current.Session
nie jest dostępna w ten kontekst.
--
Mój web.config
wygląda tak:
<configuration>
...
<system.web>
<pages enableSessionState="true">
<controls>
...
</controls>
</pages>
...
</system.web>
<sessionState cookieless="AutoDetect" mode="StateServer" timeout="22" />
...
</configuration>
Oto implementacja IRouteHandler:
public class WebPageRouteHandler : IRouteHandler, IRequiresSessionState
{
public string m_VirtualPath { get; private set; }
public bool m_CheckPhysicalUrlAccess { get; set; }
public WebPageRouteHandler(string virtualPath) : this(virtualPath, false)
{
}
public WebPageRouteHandler(string virtualPath, bool checkPhysicalUrlAccess)
{
m_VirtualPath = virtualPath;
m_CheckPhysicalUrlAccess = checkPhysicalUrlAccess;
}
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
if (m_CheckPhysicalUrlAccess
&& !UrlAuthorizationModule.CheckUrlAccessForPrincipal(
m_VirtualPath,
requestContext.HttpContext.User,
requestContext.HttpContext.Request.HttpMethod))
{
throw new SecurityException();
}
string var = String.Empty;
foreach (var value in requestContext.RouteData.Values)
{
requestContext.HttpContext.Items[value.Key] = value.Value;
}
Page page = BuildManager.CreateInstanceFromVirtualPath(
m_VirtualPath,
typeof(Page)) as Page;// IHttpHandler;
if (page != null)
{
return page;
}
return page;
}
}
Próbowałem również umieścić EnableSessionState="True"
na górze strony aspx, ale nadal nic.
HttpRequestHandler
, który implementuje IRequiresSessionState
?
Dzięki. 13 answers
Rozumiem. Całkiem głupi. To działało po tym, jak usunąłem i dodałem SessionStateModule w ten sposób:
<configuration>
...
<system.webServer>
...
<modules>
<remove name="Session" />
<add name="Session" type="System.Web.SessionState.SessionStateModule"/>
...
</modules>
</system.webServer>
</configuration>
Po prostu dodanie go nie zadziała, ponieważ "sesja" powinna być już zdefiniowana w machine.config
.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-02-10 09:19:56
Wystarczy dodać atrybut runAllManagedModulesForAllRequests="true"
do system.webServer\modules
W web.config.
Ten atrybut jest domyślnie włączony w projektach MVC i Dynamic Data.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-11-17 10:48:07
runAllManagedModulesForAllRequests=true
to naprawdę złe rozwiązanie. Zwiększyło to czas ładowania mojej aplikacji o 200%. Lepszym rozwiązaniem jest ręczne usunięcie i dodanie obiektu sesji oraz uniknięcie atrybutu run all managed modules.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-06-21 18:16:04
Dobra robota! Mam dokładnie ten sam problem. Dodawanie i usuwanie modułu sesji również działało idealnie dla mnie. Nie został jednak przywrócony przez HttpContext.Aktualne.User więc próbowałem twój mały trick z modułem FormsAuth i na pewno, że to zrobił.
<remove name="FormsAuthentication" />
<add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule"/>
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2008-12-13 02:44:27
Co powiedział @ Bogdan Maxim. Lub zmień użycie InProc, jeśli nie używasz zewnętrznego serwera stanu session.
<sessionState mode="InProc" timeout="20" cookieless="AutoDetect" />
Spójrz tutaj aby uzyskać więcej informacji na temat dyrektywy SessionState.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2008-10-20 11:30:28
Żadne z powyższych rozwiązań nie zadziałało. Dodałem następującą metodę do global.asax.cs
wtedy sesja nie była null:
protected void Application_PostAuthorizeRequest()
{
HttpContext.Current.SetSessionStateBehavior(SessionStateBehavior.Required);
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-09-22 14:50:02
Miałem podobny problem i go "rozwiązałem": ASP.NET Routing - czy niestandardowe trasy całkowicie pominąć wszystko w globalnym.asax?
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-23 12:00:31
Lepszym rozwiązaniem jest
RunAllManagedModulesForAllRequest jest sprytną rzeczą do zrobienia respect usuwania i resinserting modułu sesji.
Alk.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-10-28 17:55:50
Rozwiązanie jest wyjaśnione tutaj, http://jgvimalan.wordpress.com/2011/05/31/httpcontext-current-return-null-in-iis-7/
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-09-25 21:13:13
Wygląda na to, że zapomniałeś dodać swój adres serwera Stanowego w pliku config .
<sessionstate mode="StateServer" timeout="20" server="127.0.0.1" port="42424" />
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2008-10-20 11:10:19
Sekcja config wydaje się dźwięczna, ponieważ działa, jeśli strony są normalnie dostępne. Próbowałem innych sugerowanych konfiguracji, ale problem nadal istnieje.
Wątpię, że problem jest w dostawcy sesji, ponieważ działa bez routingu.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2008-10-20 11:43:08
Myślę, że ta część kodu wprowadza zmiany w kontekście.
Page page = BuildManager.CreateInstanceFromVirtualPath(
m_VirtualPath,
typeof(Page)) as Page;// IHttpHandler;
Również ta część kodu jest bezużyteczna:
if (page != null)
{
return page;
}
return page;
To zawsze zwróci stronę wither jest null lub nie.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2008-10-20 13:59:04
Brakowało mi odniesienia do systemu.www.mvc dll w adapterze sesji i dodanie tego samego Naprawiono problem.
Mam nadzieję, że pomoże to komuś innemu przebrnąć przez ten sam scenariusz.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-10-07 20:27:58