I have a legacy WebForms application. I need to add Azure B2C authentication to it. My application is using currently Microsoft.Aspnet.Identity. It does not have any startup.cs page. How can I make this migration?
1 Answers
Some minor things allow you to switch your site to use AAD or aadb2c for authentication. Get the necessary OWIN NuGet packages, Add some startup code to use the OWIN authentication libraries ,Register your application in AADb2c. Update your web.config with appropriate OAuth values.
Even though OWIN didn’t exist when you wrote your Web Forms app, you can still use it and it will significantly simplify the process. In the Visual Studio menu, select Tools > NuGet Package Manager > Package Manager Console.
Make sure your web project is selected in the Default project drop down. Run the below commands:
- install-package Microsoft.Owin.Host.SystemWeb
- install-package Microsoft.Owin.Security.OpenIdConnect
- install-package Microsoft.Owin.Security.Cookies
You may check the references and then follow this B2C-WebForms-DotNet
References:
- c# - ASP.NET Web Api - Startup.cs doesn't exist - Stack Overflow
- c# - OWIN Startup Class Missing - Stack Overflow
edit: My web forms if for visual C# and could find owin start up : Right click on App_Start > add item > under web , you can find it. Please check if your project is visual c# .
edit 2: Please check if below points help :
Maybe you can create new start up class by using owin library in the clas
Imports Microsoft.Owin.Extensions
Imports Microsoft.Owin.Security
Imports Microsoft.Owin.Security.Cookies
Imports Microsoft.Owin.Security.OpenIdConnect
Imports Owin
Imports System
Imports System.Configuration
Check the web.config file and remove this key setting and try
<add key="owin:AutomaticAppStartup" value="false" />
and also try add <add key="owin:AutomaticAppStartup" value="true " />
in web.config file
The following attribute will set the startup class to the StartUp class in the StartupDemo namespace.
[assembly: OwinStartup(typeof(StartupDemo.StartUp))]
Add appSetting element in the Configuration file
<appSettings>
<add key="owin:appStartup" value="StartupDemo.StartUp" />
</appSettings>
Check how owin detects start up owin-startup-class-detection -Microsoft docs
Other references:

- 8,026
- 1
- 7
- 19
-
Thank you for your answer. I did everything you suggested, but don't see Owin among the templates to add startup.cs if I add it manually, I get "Could not load file or assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b98f9f7f18d50a4m' or one of its dependencies. The system cannot find the file specified.". – David Shochet Apr 06 '22 at 13:05
-
My project is in vb.net. Maybe this is why I don't see Owin templates... Does it mean it is not doable? – David Shochet Apr 06 '22 at 13:47
-
Once try to close and open the visual studio and also check the edit in answer. And please make sure you are installing to the solution and not to any file or directory. – kavyaS Apr 06 '22 at 13:47
-
I checked the edit, that is why I mentioned that my project is in vb.net. I am installing to the main project. I had closed and opened the visual studio. – David Shochet Apr 06 '22 at 13:55
-
In case of vb.net please check the edit2 , if it can be helpful . – kavyaS Apr 06 '22 at 14:24
-
Unfortunately, I still have the same error... – David Shochet Apr 06 '22 at 17:21
-
Please try changing the assembly version or by unistalling the package and its dependencies and installing again with different version(upgrade or downgrade). Also please make sure all its dependencies are present after installation. – kavyaS Apr 11 '22 at 06:59