ASP.NET Web Api - Startup.cs doesn't exist

后端 未结 5 696
广开言路
广开言路 2021-02-01 12:43

I have an ASP.NET Web Api solution which doesn\'t contain a Startup.cs class. I presume this is because the solution wasn\'t created as an MVC solution.

All the code for

相关标签:
5条回答
  • 2021-02-01 13:22

    Startup.cs is a part of the OWIN authorization package. If the package isn't added through NuGet, I can't guarantee it would work. However, judging by this answer, it might work anyway depending on your environment.

    https://stackoverflow.com/a/24678109/6442626

    Short answer: If you installed Microsoft.Owin.Security.OAuth from NuGet, that should be good. Otherwise, you need to install it.

    Update: In order to get MVC to call the Configuration method in startup, you also need to install the Microsoft.Owin.Host.SystemWeb package from NuGet. There is nothing special you need to change with web.config, IIS will automagically detect the Owin host and load it for you.

    0 讨论(0)
  • 2021-02-01 13:30

    Yes. first you need to remove the following line from your web.config.

    <add key="owin:AutomaticAppStartup" value="false" />
    

    Only then it will call the the method it startup.cs.

    0 讨论(0)
  • 2021-02-01 13:31

    If you have installed the Owin packages, you can simple create the start up class with:

    0 讨论(0)
  • 2021-02-01 13:33

    My Startup.cs would not run until I removed this line on Web.config (in root folder)

    <add key="owin:AutomaticAppStartup" value="false" /> 
    
    0 讨论(0)
  • 2021-02-01 13:36

    You can add your own startup class, but you need to make sure that Owin is recognizing it. There are several ways to do this , but if you'd like to use a Startup class then you need to use the OwinStartup attribute.

    eg:

    [assembly: OwinStartup(typeof(MyNamespace.MyStartupClass))]
    
    0 讨论(0)
提交回复
热议问题