gpt4 book ai didi

c# - 如何在Asp Net Web Api中默认返回404

转载 作者:行者123 更新时间:2023-12-03 08:44:05 30 4
gpt4 key购买 nike

我有一个简单的Asp Net Web Api,带有一个端点,并且运行良好。但是我想,当您以我的情况调用根服务器(loclahost:8001/)时,它将返回404而不是HTTP Error 403.14 - Forbidden给我。我是ASP NET MVC的新手,已经习惯了ASP网络核心。请,我如何在这里返回404

也许路由配置会有所帮助:

public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.MapRoute(
name: "Default",
url: "{controller}/{id}",
defaults: new { controller = "GPayController"}
);
}
}

最佳答案

在web.config文件的<system.webServer>部分下添加此配置:

<system.webServer>
<handlers>
<add name="StopDirectoryBrowsing" path="*." resourceType="Directory" verb="*"
preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
<system.webServer>

关于c# - 如何在Asp Net Web Api中默认返回404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58801166/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com