简体   繁体   中英

“The given key was not present in the dictionary” ASP.NET error on IIS7

I have this error on one of my sites. Searched thought all project found no Dictionary of some kind. Read somewhere it could be caused by URL Rewrite module on IIS 7 which i'm using for certain redirects.

Error appears on all pages thought the site, 99% sure only on pages that use URL Rewriting

This is the error's stack

at System.ThrowHelper.ThrowKeyNotFoundException() 
at System.Collections.Generic.Dictionary2.get_Item(TKey key) 
at System.Data.DataView.System.Collections.IList.get_Item(Int32 recordIndex) 
at System.Web.UI.WebControls.ListViewPagedDataSource.EnumeratorOnIList.get_Current() 
at System.Web.UI.WebControls.ListView.CreateItemsWithoutGroups(ListViewPagedDataSource dataSource, Boolean dataBinding, InsertItemPosition insertPosition, ArrayList keyArray) 
at System.Web.UI.WebControls.ListView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) 
at System.Web.UI.WebControls.ListView.PerformDataBinding(IEnumerable data) 
at System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) at System.Web.UI.WebControls.DataBoundControl.PerformSelect() 
at System.Web.UI.WebControls.ListView.PerformSelect() 
at System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() 
at System.Web.UI.WebControls.ListView.CreateChildControls() 
at System.Web.UI.Control.EnsureChildControls() 
at System.Web.UI.Control.PreRenderRecursiveInternal() 
at System.Web.UI.Control.PreRenderRecursiveInternal() 
at System.Web.UI.Control.PreRenderRecursiveInternal() 
at System.Web.UI.Control.PreRenderRecursiveInternal() 
at System.Web.UI.Control.PreRenderRecursiveInternal() 
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)HTTP_CONNECTION:Keep-Alive HTTP_ACCEPT:image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-icq, */* HTTP_ACCEPT_LANGUAGE:en HTTP_COOKIE:__utma=248870149.1673016949.1252234176.1276449788.1276595165.49; __utmz=248870149.1276595165.49.55.utmcsr=search|utmccn=(organic)|utmcmd=organic|utmctr=*****; wooTracker=C1T8MWMAZWQVHJXWROHB25SO4S0B7UO0; __utmb=248870149.6.10.1276595165; __utmc=248870149; wooTracker=C1T8MWMAZWQVHJXWROHB25SO4S0B7UO0; machine-id=87.69.44.154%3A1253914747956; wooMeta=ODAwMzkmMSYxJjc1MDE5JjEyNTUyMTQwODEwMjkmMTI1NTIxNDE1NjA0OCYmMTAwJiYzMDAyODQmJiYm; _csoot=1267959625296; _csuid=X4c1ef311c39a67; ASP.NET_SessionId=zzdn5b45uqyhw145ptqhxe20 HTTP_HOST:************ HTTP_REFERER:************* HTTP_USER_AGENT:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; GTB6) HTTP_X_CEPT_ENCODING:gzip, deflate *************

Is anyone familiar with fix or at least where to look for one ?

The stack trace points to the error occurring during databinding. Could it be that in at least one case you're binding a list in your UI to a list of objects, datatable or other that does not contain a referenced column name?

Try adding this to your web.config configuration section:

<system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
</system.webServer>

On pages that have rewritten url, normally not all managed modules are executed (no Authentication etc.). If the dictionary that is accessed would be filled from such a module (like HttpContext.Current.User, which is set in that way too and would be null without that setting), then this will fix it.

it's hard to tell without more information, but I'd say you have a listview databound to a datasource that's doing a sql query, the binding includes picking off specific columns by name, and that column isn't in the result (column was renamed, column isn't in query, typo in binding, etc).

the markup for the listview, the datasource its bound to, and the codebehind for the datasource, is really what we need to help out here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM