2015-06-10 87 views
0

我可以声明这样的事情在的RegisterRoutes方法:Asp.Net MVC路由到其他网站

routes.MapRoute() (
    name: "DefaultApi", 
    url: "http://localhost:52657/api/{controller}/{id}", 
    defaults: new {id = UrlParameter.Optional } 
); 

我想访问的ASP.NET Web API(在另一个URL运行)

+0

你的问题是模糊的,增加更多的细节。谢谢, –

回答

0

没有,但你可以做一个URL重写。

要么通过URL重写模块>http://www.iis.net/downloads/microsoft/url-rewrite

或者通过代码...

public class UrlRewriteModule : IHttpModule 
{ 
    public void Init(HttpApplication context) 
    { 
     context.BeginRequest += (sender, args) => 
      { 
       var app = sender as HttpApplication; 

       if (app == null) 
       { 
        return; 
       } 

       Uri url = app.Request.Url; 

       // Allows the CSS file to be cached per Company+Version 
       if (string.Equals(url.ToString(), "http://not/what/I/want", StringComparison.OrdinalIgnoreCase)) 
       { 
        HttpContext.Current.RewritePath("https://stackoverflow.com/a/better/url"); 
        return; 
       } 
      }; 
    } 

    public void Dispose() 
    { 
    } 
} 
+0

,一定要试试这个代码 – SYSMAN