简体   繁体   English

当localhost:端口号在iis express中的浏览器地址时,web api显示403.14错误

[英]web api shows 403.14 error when localhost:port number is in browser address in iis express

This has to be something really dumb but I can't think what else to do. 这必须是非常愚蠢的东西,但我想不出还有什么可做的。

Using Visual Studio 2013 - Update 1, I created an empty web api 2 project in an existing solution, added the cross origin support (cors) package and created a basic web api controller. 使用Visual Studio 2013 - Update 1,我在现有解决方案中创建了一个空的web api 2项目,添加了跨源支持(cors)包并创建了一个基本的web api控制器。

The WebApiConfig class seems to be fine: WebApiConfig类看起来很好:

    public static void Register(HttpConfiguration config)
    {
        // Web API configuration and services
        var cors = new EnableCorsAttribute("*","*","*");
        config.EnableCors(cors);
        // Web API routes
        config.MapHttpAttributeRoutes();

        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );
    }

And also the Global.asax 还有Global.asax

    protected void Application_Start()
    {
        GlobalConfiguration.Configure(WebApiConfig.Register);
    }

I then run the application, IIS express starts normally and the browser starts with the application's url but nothing seems to work. 然后我运行应用程序,IIS express正常启动,浏览器以应用程序的url启动,但似乎没有任何工作。

If the URL is "localhost:port number" I get HTTP Error 403.14 - Forbidden The Web server is configured to not list the contents of this directory . 如果URL是“localhost:端口号”,我得到HTTP错误403.14 - 禁止Web服务器配置为不列出此目录的内容

If I try "localhost:port number/api" I get HTTP Error 404.0 - Not Found The resource you are looking for has been removed, had its name changed, or is temporarily unavailable. 如果我尝试“localhost:port number / api”,我会收到HTTP错误404.0 - 未找到您要查找的资源已被删除,名称已更改或暂时不可用。

I have looked at several blogs, tutorials, examples and I haven't seen anywhere that anything special needs to be done. 我查看了几个博客,教程,示例,我还没有看到任何特殊需要做的事情。 Could someone please shed some light in what I might be missing? 有人可以对我可能遗失的内容有所了解吗?

Web Api doesn't have a default viewable page (aspx, html, etc) that can be viewed by navigating to the root ( localhost:port in this case). Web Api没有可以通过导航到根目录查看的默认可查看页面(aspx,html等)(本例中为localhost:port )。 So that is the normal behavior. 这是正常的行为。 In order to access your Api through the controller you need to access it using the route template specified in your MapHttpRoute() method. 要通过控制器访问Api,您需要使用MapHttpRoute()方法中指定的路径模板访问它。

So to access the GET method in your Api you would open a browser and place localhost:port/api/{controllername} into the url. 因此,要在Api中访问GET方法,您将打开浏览器并将localhost:port/api/{controllername}放入url。 {controllername} would be set to the name of your controller class without Controller added to the end. {controllername}将设置为控制器类的名称,而不将Controller添加到末尾。

ex: If your controller looked like this: 例如:如果您的控制器看起来像这样:

public class TestController : ApiController {
    public HttpResponseMessage Get() {
          return something;
    }

    public HttpResponseMessage Get(int id) {
          return something with id;
    } 
}

Then your url for the first Get() would look like this: 然后你的第一个Get() url看起来像这样:

localhost:port/api/test

And the url for the second Get(int id) would look like this: 第二个Get(int id)的url如下所示:

localhost:port/api/test/5

If yours route config is OK for sure, you can try add this in Web.config: 如果您的路由配置确定无误,您可以尝试在Web.config中添加它:

<system.webServer>
 <modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 HTTP错误403.14 - 禁止使用 - 带有IIS Express的MVC 4 - HTTP Error 403.14 - Forbidden - MVC 4 with IIS Express MVC Web Api错误403.14 - MVC Web Api error 403.14 如何使用端口号(IIS Express)设置Facebook App Domains本地主机 - How to setup Facebook App Domains localhost with port number (IIS Express) IIS 8.0 Express名为“ security”的控制器的403.14禁止错误 - 403.14 forbidden error for controller named “security” with IIS 8.0 Express 当我通过 Visual Studio 中的 IIS Express 在浏览器中打开 web 应用程序时,为什么会给我这个错误? - Why give me this error when I open web app in browser through IIS Express in visual studio? 是否可以在Visual Studio 2015的其他端口中发布asp.net Web API? IIS不是IIS Express - Is it possible to publish asp.net web api in a different port in Visual Studio 2015 ? IIS not IIS Express 在windwos电话7/8中,tomcat或iis localhost端口地址是什么 - What is tomcat or iis localhost port address in windwos phone 7/8 HTTP 错误 403.14 - 禁止,本地主机:12401 - HTTP Error 403.14 - Forbidden, localhost:12401 将.NET Standard发布到IIS会引发403.14错误 - Publish .NET Standard to IIS throws 403.14 error 在带有 SpaServices 和 Visual Studio 的 IIS Express 中启动时,如何防止我的本地主机端口在调试时发生变化? - How do I prevent my localhost port from changing while debugging when launching in IIS Express with SpaServices and Visual Studio?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM