System.NullReferenceException:未将对象引用设置为对象的实例。 Dotnetnuke模块创建

时间:2014-10-29 10:48:42

标签: javascript html asp.net dotnetnuke

我在asp.net中有一个脚本,它从上一页获取产品名称,我就这样得到它:

<%
    strProductID = Convert.ToString(Request.QueryString("ProductID"))
    strLinkPath = "\DNN7\PRODUCTPDF\" + strProductID + ".pdf"
%>

并将该id指定为pdf名称,这是相同的。 我尝试从此链接标签下载此pdf:

<a runat="server" class="pdfLink" href="<% =strLinkPath %>"><% =strLinkPath %></a>

我收到错误'System.NullReferenceException: Object reference not set to an instance of an object. '

如果我将路径直接添加到标签上,它可以正常工作:

strLinkPath = "\DNN7\PRODUCTPDF\1.pdf"

此外,如果我将动态链接打印在标签中,我会获得与我手动设置的路径相同的路径,并且它与此相同:"\DNN7\PRODUCTPDF\1.pdf"但动态不起作用,我不断收到此错误。

我在这里做错了什么?

Server Error in '/DNN7' 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: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[NullReferenceException: Object reference not set to an instance of an object.]
   DotNetNuke.Entities.Urls.AdvancedUrlRewriter.Handle404OrException(FriendlyUrlSettings settings, HttpContext context, Exception ex, UrlAction result, Boolean transfer, Boolean showDebug) +165
   DotNetNuke.Entities.Urls.AdvancedUrlRewriter.RewriteUrl(Object sender, EventArgs e) +867
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +91
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +164

2 个答案:

答案 0 :(得分:0)

我删除了runat = server并将我的路径更改为此strLinkPath =“/ DNN7 / PRODUCTPDF /”+ strProductID +“。pdf”并且它有效

答案 1 :(得分:0)

对于我来说,总是由于 SQLSERVER 实例服务未启动或需要重新启动而发生此错误 解决此问题的步骤:  -打开SQL Server Management Studio。  -尝试连接到SQL实例。  -右键点击实例->停止,然后重新开始。 要么  -在Windows服务上搜索您的实例SQL Server(实例名称)  -右键单击停止,然后开始  刷新页面,它应该可以工作 希望有帮助