2014-02-24 53 views
0

我一直在嘗試在asp.net 4.0中使用url路由來爲我的網站創建一個乾淨的網址。當我在本地主機上嘗試它時,它完全像我想要的那樣工作,但是在將其上傳到Windows Azure網站後,我一直收到錯誤。您正在查找的資源已被刪除,名稱已更改或暫時不可用。在Windows Azure上的asp.net 4.0 Web應用程序的Url路由網址

我一直在努力想在這個URL中添加代碼:

,並與幾乎像上面相同的解決方案的一些其他鏈接,但沒有結果,有沒有什麼辦法來實現URL路由或任何其他方式來使Windows Azure上的ASP.NET 4.0乾淨的網址

(I不使用MVC和我將它部署Windows Azure的網站,而不是雲服務或VM)

編輯:代碼,我在Global.asax中添加 :

protected void Application_Start(object sender, EventArgs e) 
{ 
     RegisterRoutes(RouteTable.Routes); 
} 

public static void RegisterRoutes(RouteCollection routes) 
{ 
     var routeHandlerBrands = new WebFormRouteHandler<Page>("~/brands_book.aspx"); 
     var routeHandlerCategories = new WebFormRouteHandler<Page>("~/categories_fs.aspx"); 

     RouteTable.Routes.Add(new Route("Catalog/Categories", routeHandlerCategories)); 
     RouteTable.Routes.Add(new Route("Catalog/Brands", routeHandlerBrands)); 
} 

在WebFormRouteHandler:

public interface IRoutablePage 
{ 
    RequestContext RequestContext { set; } 
} 
public class WebFormRouteHandler<T> : IRouteHandler where T : IHttpHandler, new() 
{ 
    public WebFormRouteHandler(string virtualPath) 
     : this(virtualPath, true) 
    { 
    } 

    public WebFormRouteHandler(string virtualPath, bool checkPhysicalUrlAccess) 
    { 
     this.VirtualPath = virtualPath; 
     this.CheckPhysicalUrlAccess = checkPhysicalUrlAccess; 
    } 

    public string VirtualPath { get; private set; } 

    public bool CheckPhysicalUrlAccess { get; set; } 

    public IHttpHandler GetHttpHandler(RequestContext requestContext) 
    { 
     if (this.CheckPhysicalUrlAccess 
      && !UrlAuthorizationModule.CheckUrlAccessForPrincipal(this.VirtualPath 
        , requestContext.HttpContext.User 
        , requestContext.HttpContext.Request.HttpMethod)) 
      throw new SecurityException(); 

     var page = BuildManager 
      .CreateInstanceFromVirtualPath(this.VirtualPath 
      , typeof(Page)) as IHttpHandler; 

     if (page != null) 
     { 
      var routablePage = page as IRoutablePage; 
      if (routablePage != null) 
       routablePage.RequestContext = requestContext; 
     } 
     return page; 
    } 
} 

並添加處理&模塊在Web.config中:

<system.webServer> 
<modules> 
    <remove name="UrlRoutingModule-4.0" /> 
    <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" /> 
</modules> 
<handlers> 
    <remove name="ExtensionlessUrlHandler-Integrated-4.0" /> 
    <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" /> 
    <add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" type="Route.RoutingHandler, Route"/> 
</handlers>  

其作品的完美,當我調試它在本地主機或在我的本地IIS發佈,但是當我將它發佈到Windows Azure,這是行不通的

編輯2: 我我試過將它發佈到Windows Azure虛擬機,它工作(現在沒有發生錯誤),有沒有人知道任何其他方式爲Windows Azure網站(而不是虛擬機或雲)做一個乾淨的網址,或者我應該移動當前網站到虛擬機?

+0

呈現鏈接的代碼和處理/配置路由的代碼是什麼? –

+0

嗨,編輯與我使用的代碼的問題 – Kyojimaru

回答

0

重新檢查我上傳到Windows Azure的文件後,似乎忘記了上傳Global.asax文件,因此無法正常工作。在我上傳Global.asax文件後,現在它可以正常工作,難怪之前的路由不起作用。