我有一个web api,它主机在IIS上,并允许通过互联网访问。当我在请求URL中输入错误的参数时,它显示api服务器的ip地址而不是其地址。
示例:我在abc.com上托管api。我通过abc.com/api/myapi?par=kk访问api
当我请求错误的api时,它显示No HTTP resource was found that matches the request URI 'https://10.10.10.10/api/myapi
我希望它显示为abc.com/api/myapi
web api或IIS上有配置吗?
答案 0 :(得分:1)
您可以在Global.asax
中设置自定义未找到页面protected void Application_EndRequest()
{
if (Context.Response.StatusCode == 404)
{
var urlRef = Context.Request.Url;
Response.Clear();
//Set your route details here
var routedata = new RouteData();
routedata.Values["controller"] = "Home";//Your controller
routedata.Values["action"] = "Index";// Your action
//Redirect to not found page or login page
//Sample logic
IController c = new HomeController();
c.Execute(new RequestContext(new HttpContextWrapper(Context), routedata));
}
}
使用自定义视图,以便您想要显示的内容将在您的视图中