我一直在尝试在asp.net 4.0中使用url路由来为我的网站创建一个干净的网址。当我在本地主机上尝试它时,它完全像我想要的那样工作,但是在将其上传到Windows Azure网站后,我一直收到错误。您正在查找的资源已被删除,名称已更改或暂时不可用。在Windows Azure上的asp.net 4.0 Web应用程序的Url路由网址
我一直在努力想在这个URL中添加代码:
- How to implement URL rewriting with Windows Azure?
- Using Windows Azure Websites with ExtensionlessUrlHandler
,并与几乎像上面相同的解决方案的一些其他链接,但没有结果,有没有什么办法来实现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网站(而不是虚拟机或云)做一个干净的网址,或者我应该移动当前网站到虚拟机?
呈现链接的代码和处理/配置路由的代码是什么? –
嗨,编辑与我使用的代码的问题 – Kyojimaru