I'm responsible for maintaining a legacy ASP.NET website (not a web app) which contains a sizeable mix of VB and C#. I'm hoping to migrate the VB parts over to C# to have a bit more consistency.
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; as discussed here a decade ago. But, from what I can tell, that's only relevant to class libraries and API controllers.
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. 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.
My process has been:
Open the code behind (in this case:
TopMenu.ascx.vb
)Right-click anywhere in the editor panel and select the
Convert To C#
option.Sense check the newly generated
TopMenu.ascx.cs
file (it's in the right place, and seems like it should do the right thing)Change the
TopMenu.ascx
file to look atTopMenu.ascx.cs
rather thanTopMenu.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. Am I missing some obscure setting, or is this one of those "do it with a new file altogether" type processes?