The given key was not present in the dictionary
I have been tring to set up an SSO and have hit this error wall. My code is below, any assistance would be greatly apprieciated.
Thanks
Exception Details: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
Source Error:
Line 40: //Fixup the casing of the redirect URL to prevent problems with new cookies
Line 41: //being issued for a request with incorrect casing on the URL.
Line 42: redirectUrl = pages[redirectUrl];
Line 43: string baseServer = p.Request.Url.DnsSafeHost;
Source File: s:\BET_07_dev2\App_Code\Redirector.cs Line: 42
Stack Trace:
[KeyNotFoundException: The given key was not present in the dictionary.]
System.ThrowHelper.ThrowKeyNotFoundException() +28
System.Collections.Generic.Dictionary`2.get_Item(T Key key) +2635492
Redirector.PerformCentralLogin(Page p) in s:\BET_07_dev2\App_Code\Redirector.cs:42
login2.Page_Load(Object sender, EventArgs e) in s:\BET_07_dev2\login.aspx.cs:19
System.Web.Util.CalliHelper.EventArgFunctionCaller (IntPtr fp, Object o, Object t, EventArgs e) +13
System.Web.Util.CalliEventHandlerDelegateProxy.Cal lback(Object sender, EventArgs e) +45
System.Web.UI.Control.OnLoad(EventArgs e) +80
System.Web.UI.Control.LoadRecursive() +49
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3742
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''
MY CODE:
public static class Redirector
{
private static Dictionary<string, string> pages;
private static string centralLoginUrl;
static Redirector()
{
centralLoginUrl = System.Configuration.ConfigurationManager.AppSetti ngs["centralLoginUrl"];
//Register page mappings to force correct casing for the cookie
//that will eventually be issued.
pages = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase) ;
pages.Add("http://swann/central/login.aspx", "http://swann/central/login.aspx");
}
public static void PerformCentralLogin(Page p)
{
string redirectUrl = FormsAuthentication.GetRedirectUrl(string.Empty, false);
//Fixup the casing of the redirect URL to prevent problems with new cookies
//being issued for a request with incorrect casing on the URL.
redirectUrl = pages[redirectUrl];
string baseServer = p.Request.Url.DnsSafeHost;
string customRedirectUrl = "http://swann/" + redirectUrl;
p.Response.Redirect(centralLoginUrl + "?CustomReturnUrl=" +
p.Server.UrlEncode(customRedirectUrl) +
"&CustomCookiePath=" +
p.Server.UrlEncode(FormsAuthentication.FormsCookie Path));
}
}
|