这种.aspx代码有什么问题? [英] What is wrong with this type of .aspx code?

查看:67
本文介绍了这种.aspx代码有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了一点时间试图弄清楚为什么一个遗留项目不能为我编译.我只有一个错误,一个未设置对象引用",通常很容易解决,但在这种情况下,它甚至没有提供有关问题出现在哪个文件的详细信息.请参见

I'm having one bear of a time trying to figure out why a legacy project won't compile for me; I get only one error, an "Object reference not set", which is usually straightforward to fix, but in this case it provides no detail as to even which file the problem appears in. See this for the initial question, with many updates.

我怀疑很多警告,说的是同一件事("对象引用未设置为对象的实例"),而在错误后面.

I have a suspicion that the many Warnings, which say the same thing ("Object reference not set to an instance of an object") are behind the Error.

问题是,据我所知,生成这些警告的代码没有问题;但是话又说回来,我不是ASP.NET专家,当涉及到VB方面时,我当然也不是.我完全是新手.

The problem is the code that is generating these warnings is not, as far as I can tell, problematic; but then again, I'm no ASP.NET expert, and certainly not when it comes to the VB side of things, to which I am an utter newbie.

2-单击这些警告("ASP.NET运行时错误:对象引用未设置为对象的实例.")将我带到这样的行:

2-clicking these warnings ("ASP.NET runtime error: Object reference not set to an instance of an object.") takes me to lines like this:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="yanceys._Default" title="Web Order Entry" %>

这些发生在项目下面的几个文件夹中-这些文件夹有一个Default.aspx文件,在下面是Default.aspx.vb文件.

These occur in several folders beneath the Project - these folders have a Default.aspx file, beneath which is a Default.aspx.vb file.

除了Inherits元素(以下为"yanceys")中的"._Default"之前,它们看上去都相同:

They all look the same, except for what precedes the "._Default" in the Inherits element ("yanceys" below):

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="yanceys._Default" title="Web Order Entry" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Order Entry Login Page</title>
</head>
<body>
<form id="form1" runat="server">
    <div>
    </div>
</form>
</body>
</html>

Default.aspx.vb文件也相同:

And the Default.aspx.vb files are the same, too:

Namespace yanceys
    Partial Class _Default
        Inherits Page

        Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
            Session("SelectedMenu") = "Home"
            Response.Redirect("../Login.aspx?MemberNo=042")
        End Sub
    End Class
End NameSpace

...除了每个Default.aspx.vb文件唯一的命名空间(上面的"yanceys")和MemberNo(上面的"042")之外.

...except for the Namespace ("yanceys" above) and MemberNo ("042" above) which are unique for each Default.aspx.vb file.

可能是什么问题?有什么解决方案?

What could be the problem? What could be the solution?

当我对命名空间"进行全局搜索以查看可能要添加到"yanceys"的文件以使其正常工作时,对于每种此类文件,警告"的数量都膨胀为一个,所有相同的消息("ASP.NET运行时错误:对象引用未设置为对象的实例."),所有消息都与罪魁祸首指向同一行:

When I did a global search for "Namespace" to see what I might be able to prepend to "yanceys" to get it to work, the count of Warnings ballooned to one for each of this type of file, all of the same ilk ("ASP.NET runtime error: Object reference not set to an instance of an object."), all pointing to that same line as the culprit:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="yanceys._Default" title="Web Order Entry" %>

这使我认为,如果我可以解决这些警告,则错误(同一条带的错误,即对象引用未设置为对象的实例")也将得到解决.

This makes me think if I can solve these Warnings, the Error (of the same stripe, namely, "Object reference not set to an instance of an object") will also be resolved.

按照T.S.的建议,我以Admin(管理员)的身份打开VS(2013),然后依次选择File(文件)> Open Website(打开网站)...

Following T.S.'s suggestion, I opened VS (2013) as Admin, then File > Open Website...

重建工作成功;与以前一样,该版本给了我1个错误,但有一个错误:

The rebuild worked; the build gives me 1 error, as before, but a different one:

错误1使用超出应用程序级别注册为allowDefinition ='MachineToApplication'的节是错误的.此错误可能是由于未在IIS中将虚拟目录配置为应用程序引起的. C:\ MemberOrderEntry \ MembersOrderEntry \ MembersOrderEntry \ Mobile \ web.config 75

Error 1 It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS. C:\MemberOrderEntry\MembersOrderEntry\MembersOrderEntry\Mobile\web.config 75

注意::执行此操作还会导致解决方案被命名为"localhost_2030";对我来说似乎很奇怪...

NOTE: Doing this also causes the Solution to be named "localhost_2030"; that seems odd to me...

为响应T.S.的建议,我看不到将文件从代码文件"转换为代码隐藏"的任何方法.

In response to T.S.'s suggestion, I see no way to convert a file from Code File to Code-behind.

当我右键单击该项目时,会看到以下内容:

When I right-click the project, I see this:

...并且当我右键单击单个.vb文件时,我看到以下内容:

...and when I right-click an individual .vb file I see this:

为了更清楚一点,当我2单击警告"消息时,警告"(以及可能相关的盲"错误)在错误列表"中的显示如下:

To perhaps be a little clearer, the Warning (and probably associated "blind" Error) appear like so in the Error List when I 2-click the Warning message:

...有问题的文件位于项目文件夹中,如下所示:

...and the problematic file lives in a project folder as shown here:

推荐答案

我发现重建网站",并得到:

I found this written by the cat with the indecisive surname, which sounded promising, so I closed VS, deleted the two *.suo files, reopened VS ("As Administrator") and then the project, tried Build > Rebuild Web Site, and got:

Error   1   compiler initialization failed unexpectedly: Project already has a reference to assembly System.Web.Extensions. A second reference to 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Web.Extensions.dll' cannot be added. vbc : Fatal

2单击错误使我一无所获.

2-clicking the Error took me nowhere.

我想,现在呢?试图添加到System.Web.Extensions.dll的第二个引用在哪里,如何防止这种情况?

与此同时,对处理有关TFS连接的消息的不满使我绕道而走-摆脱了该项目的所有TFS痕迹.有关删除某些文件(* .vssssssssccccc等)并删除某些全局文件的答案,请此处. .sln文件中的各个部分不仅消除了这种烦恼,而且还可以解决其他问题.

Meanwhile, the irritation of dealing with messages about TFS connections sent me on a detour down that path - to rid the project of all TFS vestiges. The answers here about deleting some files (*.vsssssssssccccc and such) and removing certain global sections from the .sln file not only cleared up that irritation, but also ended up, apparently, solving the other problems.

是以下几种组合:

Deleting the .suo files
Cleaning out the TFS files and sections
Running VS as Administrator

...使项目进入最终实际运行的状态!这些怪异的错误信息由于这些旋转而消失了",似乎是魔术和意外的混合,但是我想我会接受这样的事实,即它至少最终会起作用.

...got the project to a state where it actually finally runs! It seems like a mixture of magic and serendipity that these weird err msgs "just went away" as a result of these gyrations, but I guess I'll accept the fact that it at least finally works.

也请注意(我不知道这是为什么或如何适应发生的事情),我进行的那些调整导致VS中的"WEBSITE"菜单更改为"PROJECT"

Note, too (I don't know why or how this fits into what happened), that something in those tweaks I made caused the "WEBSITE" menu in VS to change to "PROJECT"

今天,菜单已经从PROJECT更改为WEBSITE,从返回,但它仍在构建和运行,所以我想我会惊scratch不已,然后继续.

And today the menu has changed back, from PROJECT to WEBSITE, but it still builds and runs, so I guess I'll just scratch my head in consternation and blithely continue on.

这篇关于这种.aspx代码有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆