在 Asp.Net Webform 应用程序中使用路由
我在 Asp.Net Webform 应用程序中使用 System.Web.Routing 。我在 global.asax
中编写了以下路由
routes.RouteExistingFiles = true; // I made true/false both, but none works
routes.Add("competition", new Route
(
"Test",
new CustomRouteHandler("~/Test/WebForm1.aspx")
));
,目录结构如下:-
申请
|
|--- 测试(文件夹)
<前><代码> |--- Webform1.aspx
当我在浏览器中写入 http://localhost:xxxx/Test/
(使用 Casini)时,请求以传统方式处理,而不是通过路由,并且,它给了我“目录列表 - /test/”页面。
你能帮我一下吗?
I am using System.Web.Routing
in the Asp.Net Webform Application. I wrote the following route in the global.asax
routes.RouteExistingFiles = true; // I made true/false both, but none works
routes.Add("competition", new Route
(
"Test",
new CustomRouteHandler("~/Test/WebForm1.aspx")
));
And the directory structure is the following:-
Application
|
|--- Test (Folder)
|--- Webform1.aspx
When I write in the browser http://localhost:xxxx/Test/
(using Casini), the request is handle in the traditional manner not through the routes, and, it gives me the "Directory Listing -- /test/" page.
Could you please help me out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我遇到了同样的问题,我选择了实用的解决方案,即应处理默认路径的文件称为 Default.aspx
I had the same problem, and I chose the pragmatic solution that the file that should handle the default path is called Default.aspx
您是否直接使用 WebForms 的路由,我刚刚专门为“WebForms”实现了这一点,因为有一些事情需要注意:
http://haacked.com/archive/2008/03/11/using-routing-with-webforms.aspx
HTH
更新:
使用链接中的实现仍然会产生相同的错误,因为实际文件夹存在。
我认为,由于该文件夹存在,因此将提供该文件夹(在某些情况下可能需要列出文件夹内容),
也许采取不同的方法会更好,例如,如果页面全部指向特定的外联网登录页面,则可能需要额外的描述性文件夹可以工作,例如:/Extranets/Test/?
Are you using Routing straight out the box for WebForms, I have just implemented this for "WebForms" specifically, since there is some things to be aware of:
http://haacked.com/archive/2008/03/11/using-routing-with-webforms.aspx
HTH
Update:
Using the implementation in the link still produces the same error, since the actual folder exists.
I would think that since the folder exists, it would be served (in some cases listing the folder contents may be desired)
Maybe taking a different approach would be better for instance, if the pages all point to specific extranet login pages maybe an extra descriptive folder would work, eg: /Extranets/Test/ ?