使用路由处理程序进行URL路由

编程入门 行业动态 更新时间:2024-10-04 19:35:53
本文介绍了使用路由处理程序进行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>

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

更多推荐

使用路由处理程序进行URL路由

本文发布于:2023-11-02 06:36:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1551634.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路由   程序   URL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!