【发布时间】:2018-01-24 23:03:28
【问题描述】:
我有网站项目,我已经开始开发 api(至少在尝试)。
问题在于创建 Global.asax 文件。因为这是Web Site Project,所以当我创建Global Application Class 时,它只创建Global.asax 而没有Global.asax.cs
经过一番研究,我发现我需要手动完成,所以我创建了Global.asax.cs 文件,它自动将它设置在我已经创建的Global.asax 下,我认为这很好。
问题是我认为Global.asax.cs 中的代码没有运行。我尝试在Global.asax - Application_Start function 中放置断点,它停在那里(这意味着它正在工作),但是当我在Global.asax.cs 做同样的事情时,它并没有停止。
我尝试在Global.asax 中添加<%@ Application Language="C#" Inhertis="Global.asax"%>,但我得到的是Could not load type 'Global.asax'
我该怎么办?
编辑:
Global.asax.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Routing;
/// <summary>
/// Summary description for Global
/// </summary>
///
public class Global
{
public Global()
{
//
// TODO: Add constructor logic here
//
}
void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = System.Web.Http.RouteParameter.Optional });
}
}
【问题讨论】:
标签: c# asp.net global-asax web-site-project