简体   繁体   中英

403.14 - Forbidden when controller name and controller directory name is same in IIS

I have below code where my controller name is Customer and it is part of the Customer directory in my web api 2 project. It seems that IIS doeasn't allow me to use same directory name and controller name as it is throwing error 403 for get call ( https://hostname:443/myapp/customers ). I think this will not be a problem after deploying the code but in order to debug on my local machine how can I make this working on my local?

[RoutePrefix(RoutePrefix)]
public class CustomersController : ApiController
{
    const string RoutePrefix = @"customers";

    private readonly ICustomersData _customersData;

    public CustomersController(ICustomersData customersData
    {
        _customersData = customersData
    }

    /// <summary>
    /// Get Customers
    /// </summary>
    /// <returns>Customers</returns>
    [ResponseType(typeof(Customer[]))]
    [HttpGet, Route("")]
    public IHttpActionResult GetCustomers()
    {
        var customers = _customersData.GetCustomers();

        return Ok(customers);
    }
}

The routing system checks the file system to see if a URL matches a file/folder on the disk. If it finds a match, the routing is ignored and the request bypassed any route entries so that the file will be served directly. This is important for static HTML, JS, images etc.

So in this case, the controller folder matches the URL and tried to server the contents of the directory instead. To fix this you can set the RouteExistingFiles property to true in your routing config:

routes.RouteExistingFiles = true;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM