Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old May 25th, 2006, 01:48 PM
Registered User
 
Join Date: Apr 2006
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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));
    }
}




  #2 (permalink)  
Old May 26th, 2006, 12:07 PM
Registered User
 
Join Date: Apr 2006
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

FYI - I fixed the error. I had to make two changes one in the way I was casing the items in the dictionary and two at the customRedirectUrl. i.e.
pages.Add("/bet_07_dev2/login.aspx", "/bet_07_dev2/login.aspx");
and
string customRedirectUrl = "http://serverName" + redirectUrl;



Similar Threads
Thread Thread Starter Forum Replies Last Post
Item has already been added. Key in dictionary CBS General .NET 2 November 23rd, 2006 10:07 AM
How to check if query's are present in a database rmsmit VB How-To 6 December 13th, 2005 11:48 AM
In which Namespace the ObjectList Classs present sreenugotla General .NET 0 March 21st, 2005 05:08 AM
How to Validate a Date for present and Future Cute Designer J2EE 1 November 9th, 2004 10:45 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.