c# - ASP.NET Web Api - Startup.cs 不存在

标签 c# asp.net .net asp.net-mvc asp.net-mvc-4

我有一个不包含 Startup.cs 类的 ASP.NET Web Api 解决方案。我认为这是因为该解决方案不是作为 MVC 解决方案创建的。

启动的所有代码都在 Global.asax.cs 文件中定义,如下所示

public class Global : HttpApplication
{
    void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup
        AreaRegistration.RegisterAllAreas();
        GlobalConfiguration.Configure(WebApiConfig.Register);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
    }
}

但是,现在我想要支持 OAuth,我找到的所有文档都基于具有以下类的 Startup.cs

public partial class Startup
{
    public void Configuration(IAppBuilder app)
    {
        ConfigureAuth(app);
    }
}

是否可以只在我的解决方案中添加这个新类并且解决方案将继续工作?

这会不会与 Global.asax.cs 类有任何冲突?

编辑:在我添加了 Startup.cs 类之后,我无法到达我添加到其中的断点......

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.Owin;
using Owin;

[assembly: OwinStartup(typeof(MyGame.Startup))]

namespace MyGame
{
    public partial class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            ConfigureAuth(app);
        }
    }
}

知道发生了什么吗?

最佳答案

如果您已经安装了 Owin 包,您可以简单地创建启动类:

enter image description here

关于c# - ASP.NET Web Api - Startup.cs 不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43076150/

相关文章:

c# - 如何解决 Unable to cast object of type 'System.Data.DataView' to type 'System.Data.DataTable' ERROR

c# - 拖放需要数学修复

asp.net - 使用 jQuery 突出显示选定的 ASP.NET DataGrid 行

javascript - 从我的网站查询第三方网站的数据库

asp.net - XML 包中的 Google 跟踪代码管理器脚本解析错误

c# - 作为 C# 程序员,我应该学习 Openedge 吗?

c# - 在监 window 口中评估动态属性

c# - Visual C# Windows 窗体应用程序中的字符频率

c# - WPF 弹出窗口 : open with animation

c# - 将 MenuItem 与列表中的项目动态关联