C# 如何调试单个 ASPX 文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15538520/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you debug a single ASPX file?
提问by xarzu
How do you debug a single ASPX file?
如何调试单个 ASPX 文件?
I am somewhat new to ASPX files, but I am not new to C#.
我对 ASPX 文件有点陌生,但我对 C# 并不陌生。
I figured that all asp.net c# projects were run on the server as compiled code. And so there was some sort of binary file somewhere somehow or maybe a XAP file like they have with silverlight.
我认为所有 asp.net c# 项目都作为编译代码在服务器上运行。所以在某处有某种二进制文件,或者可能是像 Silverlight 那样的 XAP 文件。
But it seems that this is not the case. it seems that, sometimes, you can have an ASPX file along with the code-behing C Sharp file and it runs just like a PHP file. For starters, is that right? Am I right so far?
但似乎并非如此。似乎有时,您可以将 ASPX 文件与代码行为 C Sharp 文件一起使用,并且它的运行方式就像一个 PHP 文件。首先,对吗?到目前为止我是对的吗?
Now, if I was the owner of both the ASPX file and the CSHARP code-behind file, how would I go about debugging it in Visual Studio?
现在,如果我是 ASPX 文件和 CSHARP 代码隐藏文件的所有者,我将如何在 Visual Studio 中调试它?
How do I run the code?
我如何运行代码?
My point is that there is no project to load. There is only a file.
我的观点是没有要加载的项目。只有一个文件。
After setting a break point, there is nothing to run. I have tried attaching to the browser that has the aspx code loaded but then the breakpoints become inactive.
设置断点后,就没什么可运行的了。我尝试附加到加载了 aspx 代码的浏览器,但随后断点变为非活动状态。
the file is https://www.seattleu.edu/admission/nonMatricLander.aspx
该文件是https://www.seattleu.edu/admission/nonMatricLander.aspx
and out on the server there is just the aspx file and the accompanying .cs file
在服务器上只有 aspx 文件和随附的 .cs 文件
That is all there is. There is no solution file, there is no default.aspx file there is nothing else in the that directory apart from other .aspx files and aspx.cs files.
这就是全部。没有解决方案文件,没有 default.aspx 文件,该目录中除了其他 .aspx 文件和 aspx.cs 文件之外没有其他任何内容。
If it was a web form, there would be a project file and and or a solution file. There would be something compiled, right? There is nothing like that. there are no dll files
如果它是一个网络表单,就会有一个项目文件和/或一个解决方案文件。会有一些编译,对吧?没有什么是这样的。没有dll文件
采纳答案by Alexei Levenkov
Assuming you've already got ASPX page to render on local IIS server (i.e. by dropping to folder for default site).
假设您已经将 ASPX 页面呈现在本地 IIS 服务器上(即通过拖放到默认站点的文件夹)。
In Visual Studio
在 Visual Studio 中
- Open page (from localhost:....) in browser of your choice
- Debugger -> Attach To process
- See if w3wp is in the list, if not check "show from all users" checkbox, may need to run VS as admin (or user that have debug privileges)
- Attach to w3wp (make sure to pick correct .Net version if necessary)
- Open ASPX/ASPX.cs from and set breakpoints
- Refresh page in browser to hit breakpoints
- 在您选择的浏览器中打开页面(来自 localhost:....)
- 调试器 -> 附加到进程
- 查看w3wp是否在列表中,如果没有选中“从所有用户显示”复选框,可能需要以管理员身份(或具有调试权限的用户)运行VS
- 附加到 w3wp(如有必要,请确保选择正确的 .Net 版本)
- 从打开 ASPX/ASPX.cs 并设置断点
- 在浏览器中刷新页面以命中断点
Note: creating one of Web projects would be easier as you will be able to use local server provided by VS and easier overall experience.
注意:创建一个 Web 项目会更容易,因为您将能够使用 VS 提供的本地服务器和更轻松的整体体验。
回答by floppsb
Typically, the DLL file will not be colocated with the actual aspx page. The c-sharp file has to be compiled into a DLL or the page won't be able to run. Two distinct possibilities come to mind: 1.) The DLL file is located in another folder and you can't see it or don't have permissions to see it, or 2.) The page was designed in Visual Studio originally, but was changed to utilize jQuery or JavaScript to handle the form submission. One clue:
通常,DLL 文件不会与实际的 aspx 页面位于同一位置。c-sharp 文件必须编译成 DLL,否则页面将无法运行。我想到了两种不同的可能性:1.) DLL 文件位于另一个文件夹中,您看不到它或没有查看它的权限,或者 2.) 该页面最初是在 Visual Studio 中设计的,但是改为使用 jQuery 或 JavaScript 来处理表单提交。一个线索:
<input type="submit" name="ctl00$ctl00$MainContentPlaceholder$cphBody$btnSubmit"
value=" "
onclick="$(this).hide();$('#Processing').show();return true;
;WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ctl00$MainContentPlaceholder$cphBody$btnSubmit", "",
true, "", "", false, false))"
id="ctl00_ctl00_MainContentPlaceholder_cphBody_btnSubmit" class="btnSubmit">
WebForm_DoPostBackWithOptions is a .NET specific function - I think you're probably missing the DLL and it located elsewhere within the website.
WebForm_DoPostBackWithOptions 是 .NET 特定的函数 - 我认为您可能缺少 DLL,它位于网站内的其他位置。
To debug the actual aspx/aspx.cs file itself, I would recommend just placing both in a project. It is much easier than trying to move around in the IIS Manager.
要调试实际的 aspx/aspx.cs 文件本身,我建议将两者都放在一个项目中。这比尝试在 IIS 管理器中移动要容易得多。