我有一个搜索控件,当用户单击搜索时,查询将通过后面的代码中的以下行传入 url(获取模式):
Server.Transfer("portfolio_search_results.aspx?search=" + query);
现在我有一个非常奇怪的问题,如果用户点击搜索按钮搜索工作正常,但如果用户再次点击搜索错误
你调用的对象是空的。
正在提高。搜索后转到其他页面并再次搜索工作正常,只有连续两次单击搜索按钮时才会发生这种情况。搜索控件位于主页面的顶部。搜索功能中的代码:
SqlCommand cmd = new SqlCommand("something", _mainConnection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("ID", SessionManager.Session[SessionParam.ID].ToString()));
cmd.Parameters.Add(new SqlParameter("Type", type));
return _mainDb.ExecuteDataSet(cmd).Tables[0];
并且错误在会话中。
如果我使用的是 Response.Redirect 而不是 Server.Transfer 它根本不起作用,即使在第一次搜索时也会出现上述错误。
编辑:添加堆栈跟踪。
Server Error in '/' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
[No relevant source lines]
Source File: c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\e76777bb\bf0abb72\App_Web_portfolio_search_results.aspx.cdcab7d2.jiztmxz2.0.cs Line: 0
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
Appeals.GetAppeals(String typeAppeals) +104
search.make_dt() +21
search..ctor() +311
portfolio_search_results..ctor() +26
ASP.portfolio_search_results_aspx..ctor() in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\e76777bb\bf0abb72\App_Web_portfolio_search_results.aspx.cdcab7d2.jiztmxz2.0.cs:0
__ASP.FastObjectFactory_app_web_portfolio_search_results_aspx_cdcab7d2_jiztmxz2.Create_ASP_portfolio_search_results_aspx() in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\e76777bb\bf0abb72\App_Web_portfolio_search_results.aspx.cdcab7d2.jiztmxz2.1.cs:0
System.Web.Compilation.BuildResultCompiledType.CreateInstance() +32
System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp, Boolean noAssert) +119
System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +33
System.Web.UI.PageHandlerFactory.System.Web.IHttpHandlerFactory2.GetHandler(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +40
System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig) +160
System.Web.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +93
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
Version Information: Microsoft .NET Framework Version:2.0.50727.3634; ASP.NET Version:2.0.50727.3634