Question

I've been trying to use url routing in asp.net 4.0 to make a clean url for my website. when I try it in localhost, it works perfectly just like what I want, but after I upload it to Windows Azure Website, I keep getting error The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

I've been trying to add code like in this URL :

and some other link with almost the same solution like the above but with no result, are there any way to implement URL Routing or any other way to make a clean url with asp.net 4.0 on Windows Azure

(I don't use MVC and I deploy it on Windows Azure Website, not Cloud Service or VM)

Edit: The code that I add in 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));
}

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

And add handler & modules in 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>    

it work's perfectly when I debug it in localhost or publish it in my local IIS, but when I publish it to Windows Azure, it doesn't work

Edit 2: I've tried to publish it to Windows Azure Virtual Machine and it's working ( no error occured for now ), did anyone know any other way to make a clean url for windows azure website ( not virtual machine or cloud ), or I should move my current Website to the Virtual Machine?

Was it helpful?

Solution

After rechecking the file that I've uploaded to Windows Azure, it seems that I forgot to upload the Global.asax file, so it doesn't work. And after I uploaded the Global.asax file, now it works perfectly, no wonder that the routing doesn't work before.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top