简体   繁体   English

使用ASP.NET 4 Web表单进行URL路由

[英]URL Routing with ASP.NET 4 Web Forms

I have ASP.NET webFroms application on my local, when i try to use this following rout I get 404 not found error. 我在本地有ASP.NET webFroms应用程序,当我尝试在溃逃后使用此应用程序时,出现404 not found错误。 I am trying to go to mylocalsite.com/home that should resolve to ~/Default.aspx, what can be the issue? 我正在尝试访问应解析为〜/ Default.aspx的mylocalsite.com/home,这可能是什么问题? I did try many ways and followed on MSDN help on http://msdn.microsoft.com/en-us/library/cc668202.aspx but cant make it to work so that I can create the routs that i need. 我确实尝试了许多方法,并在http://msdn.microsoft.com/zh-cn/library/cc668202.aspx上获得了MSDN帮助,但无法使其正常工作,因此我可以创建我需要的溃败。 the site is running on IIS7. 该站点在IIS7上运行。

this following code is in my Global.asax 以下代码在我的Global.asax中

public static void RegisterRoutes(RouteCollection routes)
        {

            routes.MapPageRoute("homepage", "/home", "~/Default.aspx");

        }

        protected void Application_Start(object sender, EventArgs e)
        {
            RegisterRoutes(RouteTable.Routes);


        }

A route cannot start with / . 路由不能以/开头。 Try: 尝试:

routes.MapPageRoute("homepage", "home", "~/Default.aspx");

Also make sure that your application pool is configured to run in Integrated Pipeline mode in IIS 7.0 in order for extensionless urls such as /home to work. 还要确保将您的应用程序池配置为在IIS 7.0中以集成管道模式运行,以使无扩展名的URL(例如/home正常工作。

MapPageRoute方法的第二个参数是路由的URL模式,即您在服务器/应用程序名称后看到的路径,您不应为其指定“ /”。

thanks for all of your help, and I finally found what was my exact problem, you can see it in below link, my main issue was HTTP Redirection feature was not enabled in windows features --> World wide web Services --> Common HTTP Features --> HTTp Redirection 感谢您的所有帮助,我终于找到了我的确切问题,您可以在下面的链接中看到它,我的主要问题是Windows功能中未启用HTTP重定向功能->万维网服务->通用HTTP功能-> HTTp重定向

full steps for fix: ASP.NET 4.0 URL Routing HTTP Error 404.0 - Not Found 修复的完整步骤: ASP.NET 4.0 URL路由HTTP错误404.0-找不到

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM