我正在阅读使用ASP.NET设计Evolvable Web API.在其中一个练习中,本书让我使用Visual Studio编辑Controller.这是在使用C#的ASP.NET中完成的.我使用的模板是标准的ASP.NET Web应用程序API.
我已经按照书中显示的方式编辑了控制器(虽然它似乎没有给出非常具体的指示).这是我的控制器的样子.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Security.Claims;
using System.Security.Cryptography;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http;
using System.Web.Http.ModelBinding;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.AspNet.Identity.Owin;
using Microsoft.Owin.Security;
using Microsoft.Owin.Security.Cookies;
using Microsoft.Owin.Security.OAuth;
using WebApplication4.Models;
using WebApplication4.Providers;
using WebApplication4.Results;
namespace WebApplication4.Controllers
{
public class GreetingController : ApiController
{
public string GetGreeting() {
return "Hello World!";
}
}
public static List<Greeting> _greetings = new List<Greeting>();
public HttpResponseMessage PostGreeting(Greeting greeting)
{
_greetings.Add(greeting);
var greetingLocation = new Uri(this.Request.RequestUri, "greeting/" + greeting.Name);
var response = this.Request.CreateResponse(HttpStatusCodeResult.Created);
response.Headers.Location = greetingLocation;
return response;
}
}
Run Code Online (Sandbox Code Playgroud)
我收到错误:
<invalid-global-code >不包含'request'的定义,| 归档时间: |
|
| 查看次数: |
5270 次 |
| 最近记录: |