2017-04-03 55 views
0

自定義網頁API錯誤消息我有一個Web API,它的主機上IIS和它允許通過互聯網訪問。當我輸入錯誤的參數在請求的URL,它顯示了API服務器,而不是它的地址的IP地址。 例:I上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 是否有網頁API或IIS配置任何?當URL不匹配

回答

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)); 
    } 
} 

使用自定義視圖,以便你要顯示將會在你看來什麼都