From ae7167a29703d9b20b0ebd32ab666aa79cf92025 Mon Sep 17 00:00:00 2001 From: Vincent He Date: Mon, 26 Sep 2016 11:38:16 +0800 Subject: [PATCH] Fix an error --- .../Routing/HttpConfigurationExtensions.cs | 2 +- .../Utils/ODataSessionIdManager.cs | 42 +++++++++++++++++-- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.Restier.Publishers.OData/Routing/HttpConfigurationExtensions.cs b/src/Microsoft.Restier.Publishers.OData/Routing/HttpConfigurationExtensions.cs index c56edff1..e83747e8 100644 --- a/src/Microsoft.Restier.Publishers.OData/Routing/HttpConfigurationExtensions.cs +++ b/src/Microsoft.Restier.Publishers.OData/Routing/HttpConfigurationExtensions.cs @@ -113,7 +113,7 @@ public static void SetUseVerboseErrors(this HttpConfiguration configuration, boo CultureInfo.InvariantCulture, Resources.ArguementsCannotbeNull, "configuration")); } - configuration.Properties[useVerboseErrors] = useVerboseErrors; + configuration.Properties[UseVerboseErrorsFlagKey] = useVerboseErrors; } /// diff --git a/test/ODataEndToEnd/Microsoft.Restier.Providers.InMemory/Utils/ODataSessionIdManager.cs b/test/ODataEndToEnd/Microsoft.Restier.Providers.InMemory/Utils/ODataSessionIdManager.cs index a00d91fb..70c31dbc 100644 --- a/test/ODataEndToEnd/Microsoft.Restier.Providers.InMemory/Utils/ODataSessionIdManager.cs +++ b/test/ODataEndToEnd/Microsoft.Restier.Providers.InMemory/Utils/ODataSessionIdManager.cs @@ -21,21 +21,57 @@ public string CreateSessionID(HttpContext context) public string GetSessionID(HttpContext context) { - var id = HttpContext.Current.Items["AspCookielessSession"] as string; + var id = context.Items["AspCookielessSession"] as string; + if (!string.IsNullOrEmpty(id)) + { + return id; + } // Azure web site does not support header "AspFilterSessionId", so we cannot get context.Items["AspCookielessSession"] // for azure web site use, Headers["X-Original-URL"] format: /(S(xxx))/odata/path. - var originalUrl = HttpContext.Current.Request.Headers["X-Original-URL"]; + var originalUrl = context.Request.Headers["X-Original-URL"]; if (!string.IsNullOrEmpty(originalUrl)) { - var match = Regex.Match(HttpContext.Current.Request.Headers["X-Original-URL"], @"/\(S\((\w+)\)\)"); + var match = Regex.Match(originalUrl, @"S\((\w+)\)"); if (match.Success) { id = match.Groups[1].Value; + return id; } } + // Starting 2016/09/18, Azure request header does not contains X-Original-URL + // Note session will always null, URL parsing does not work neither + originalUrl = context.Request.Headers["AspFilterSessionId"]; + if (!string.IsNullOrEmpty(originalUrl)) + { + var match = Regex.Match(originalUrl, @"S\((\w+)\)"); + if (match.Success) + { + id = match.Groups[1].Value; + return id; + } + } + + // Try some cookieless logic + originalUrl = context.Request.Params["HTTP_ASPFILTERSESSIONID"]; + if (!string.IsNullOrEmpty(originalUrl)) + { + var match = Regex.Match(originalUrl, @"S\((\w+)\)"); + if (match.Success) + { + id = match.Groups[1].Value; + return id; + } + } + + var cookie = context.Request.Cookies["ASP.NET_SessionId"]; + if (cookie != null) + { + return cookie.Value; + } + return id; }