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

System.NullReferenceException: Object reference not set to an instance of an object. Dotnetnuke module creation

本文关键字:实例 Dotnetnuke 模块 创建 对象 NullReferenceException 对象引用 设置 System      更新时间:2023-09-26

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

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

并且u将该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

我删除了runat=服务器,并将路径更改为此strLinkPath="/DNN7/PRODUCTPDF/"+strProductID+".pdf",它在上运行

对于我来说,发生此错误总是因为SQLSERVER实例服务未启动或需要重新启动解决此问题的步骤:-打开sqlserver管理工作室。-尝试连接到sql实例。-右键单击实例->停止,然后重新启动。或-在windows服务上搜索您的实例SQL Server(实例名称)-右键单击"停止",然后启动刷新你的页面,它应该可以工作希望这能帮助