[英]Gradually migrating ASP.NET website to use solely C#
I'm responsible for maintaining a legacy ASP.NET website (not a web app) which contains a sizeable mix of VB and C#.我负责维护包含大量 VB 和 C# 的旧版 ASP.NET 网站(不是 Web 应用程序)。 I'm hoping to migrate the VB parts over to C# to have a bit more consistency.
我希望将 VB 部分迁移到 C# 以获得更多的一致性。
Now I know you can use the <codeSubDirectories>
tag in the web.config
to indicate that certain code folders need to be rendered in a particular language;现在我知道您可以使用
web.config
中的<codeSubDirectories>
标记来指示某些代码文件夹需要以特定语言呈现; as discussed here a decade ago. 正如十年前在这里讨论的那样。 But, from what I can tell, that's only relevant to class libraries and API controllers.
但是,据我所知,这仅与类库和 API 控制器有关。
I have this Code Converter extension installed on Visual Studio, which allows you to convert one file at a time, it seems to work brilliantly in terms of converting the file.我在 Visual Studio 上安装了这个代码转换器扩展,它允许您一次转换一个文件,它在转换文件方面似乎工作得很好。 My issue is that when debugging the new code to check it's definitely doing the right thing - it doesn't seem to hit the new code behind at all.
我的问题是,在调试新代码以检查它肯定在做正确的事情时 - 它似乎根本没有击中新代码。
For a proof of concept, I'm using the ascx
file for my nav menu - it doesn't do anything fancy, just shows and hides some parts based on whether or not the user is in certain roles.作为概念验证,我在导航菜单中使用了
ascx
文件——它没有做任何花哨的事情,只是根据用户是否处于某些角色来显示和隐藏某些部分。
My process has been:我的过程是:
Open the code behind (in this case: TopMenu.ascx.vb
)打开后面的代码(在本例中:
TopMenu.ascx.vb
)
Right-click anywhere in the editor panel and select the Convert To C#
option.右键单击编辑器面板中的任意位置,然后选择“
Convert To C#
选项。
Sense check the newly generated TopMenu.ascx.cs
file (it's in the right place, and seems like it should do the right thing)感觉检查新生成的
TopMenu.ascx.cs
文件(它在正确的位置,似乎它应该做正确的事情)
Change the TopMenu.ascx
file to look at TopMenu.ascx.cs
rather than TopMenu.ascx.vb
更改
TopMenu.ascx
文件以查看TopMenu.ascx.cs
而不是TopMenu.ascx.vb
So now the top line is:所以现在最重要的是:
<%@ Control Language="C#" AutoEventWireup="false" CodeFile="TopMenu.ascx.cs" Inherits="Menus_TopMenu" %>
Which mimics the structure of other ascx
files or aspx
files that are looking at C# - however, when debugging the new file - it just doesn't hit the codebehind at all.它模仿了其他
ascx
文件或正在查看 C# 的aspx
文件的结构 - 但是,在调试新文件时 - 它根本不会触及代码隐藏。 Am I missing some obscure setting, or is this one of those "do it with a new file altogether" type processes?我是否缺少一些晦涩的设置,或者这是“完全使用新文件”类型的过程之一?
最后,我的解决方案是重命名旧文件(即更改为TopMenu - VB.aspx
),然后使用 C# 将其全部复制并粘贴到新文件中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.