我在现有的web项目中添加了asp.net标识。现在我的控制器无法访问。如果我启动本地浏览器,我可以成功登录。但是当我去一个像
这样的旧控制器时namespace PortwatchServiceV003.Controllers
{
[Authorize]
public class ValuesController : ApiController
{
// GET api/values
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/values/5
public string Get(int id)
{
return "value";
}
// POST api/values
public void Post([FromBody]string value)
{
}
// PUT api/values/5
public void Put(int id, [FromBody]string value)
{
}
// DELETE api/values/5
public void Delete(int id)
{
}
}
}
它找不到错误404。 网址是否以某种方式改变了?
webapiconfig下面......
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.Services.Add(typeof(IExceptionLogger), new App_Start.AiExceptionLogger());
//config.EnableCors();
//var cors = new EnableCorsAttribute("http://localhost:57007", "*", "*");
//config.EnableCors(cors);
// Web API configuration and services
// Configure Web API to use only bearer token authentication.
config.SuppressDefaultHostAuthentication();
config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));
//use https ONLY
//config.Filters.Add(new UseSSLAttribute());
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
var json = config.Formatters.JsonFormatter;
json.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects;
config.Formatters.Remove(config.Formatters.XmlFormatter);
config.Formatters.JsonFormatter.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.Indented;
config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
}
}