使用路由处理程序进行URL路由 [英] Url Routing using Route Handler

查看:78
本文介绍了使用路由处理程序进行URL路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨。



i希望使用路由处理程序路由网址我尝试了一些代码,但它没有用完。

<全局页面中的




Hi.

i want to route url using route handler i tried some code but it doesn''t work out.

in Global page:

RouteTable.Routes.Clear();
     RouteTable.Routes.Add("MyCustomRoute", new Route("{Name}", new CustomRouteHandler("~/Index.aspx")));





和实施处理程序的类是





and the class which implements handler is

public class CustomRouteHandler : IRouteHandler {

  
    IHttpHandler IRouteHandler.GetHttpHandler(RequestContext requestContext)
    {
        string virtualPath = "~/Index.aspx";

        return BuildManager.CreateInstanceFromVirtualPath(virtualPath, typeof(Page)) as IHttpHandler;
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}




索引页中的






in index page:

string a =(string) Page.RouteData.Values["Name"];



我正在尝试四天。我无法理解我哪里出错了...请帮助我。我在另一个项目中试过的相同代码。我无法在我的项目中做到这一点..



错误:HTTP 404.您正在寻找的资源(或其中一个依赖项)可能已被删除,更改名称,或暂时不可用。请查看以下网址,确保拼写正确。



在此先感谢..


i am trying for this since four days. i cant able to understand where i am going wrong...please help me.the same code i tried in another project it is working there. i cant able to do it in my project..

Error: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Thanks in advance..

推荐答案

你的问题不是那么清楚。

在某些情况下,当您的重写URL指向无物理页面时,URL重写会出现404问题。这个问题可以通过

在你的web.config文件中添加这个标签来解决



your problem is not so much clear.
in some case regarding URL rewriting when your rewrite URL point to none exists physical page then 404 problem occured. and this problem can be solved by
add this tag in your web.config file

<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
...
</modules>
</system.webServer>





http:// codingsack.com/question/5/global.asax-application-beginrequest-not-firing-problem-occurs-during-.html [ ^ ]


这篇关于使用路由处理程序进行URL路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆