我正在通过一个在线教程学习ASP.NET(构建Web应用程序)。问题是当我重复使用导师的代码时,我遇到了这个错误:
Error 1 The type or namespace name 'Uri' could not be found (are you missing a using directive or an assembly reference?)
我尝试包含多个命名空间(例如System.Uri),但它们都无法工作。有人知道问题出在哪里,以及我需要做什么来解决这个问题吗?
以下是代码:
using System.Collections.Generic;
using System.Net;
using System.Linq;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Web;
using System.Web.Http;
using System.Net.Http;
using System.Data.Entity.Infrastructure;
using System.Uri;
public HttpResponseMessage Post(Friend friend)
{
if (ModelState.IsValid)
{
db.Friends.Add(friend);
db.SaveChanges();
HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, friend);
response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = friend.FriendId }));
return response;
}
else
{
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
}
}