ASP.NET 4.0 URL路由HTTP错误404.0-找不到 [英] ASP.NET 4.0 URL Routing HTTP Error 404.0 - Not Found

查看:162
本文介绍了ASP.NET 4.0 URL路由HTTP错误404.0-找不到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用以下路由在ASP.NET 4.0中实现了URL路由。

  routes.MapPageRoute(
NewsDetails,//路由名称
news / {i} / {* n},//路由URL
〜/ newsdetails.aspx //处理路由
的网页);

这给了我

  http://www.mysie.com/news/1/this-is-test-news 

,这在我的本地主机上正常工作。



但是当我将其上传到服务器时,它给出了...

 服务器错误

404-找不到文件或目录。
您正在寻找的资源可能已被删除,名称更改,
或暂时不可用。

如果我尝试 http://www.mysie.com/news/1/this-is-test-news.aspx ,然后显示页面。 / p>

有人遇到同样的问题吗?



我如何设置URL
http://www.mysie.com/news/1/this-is-test-news 在Windows Server 2008上工作吗?

解决方案

要使用IIS 7.5启用默认ASP.Net 4.0路由:


  1. 确保已安装 HTTP重定向功能
    可以完成->控制面板-> Progams ->关闭Windows功能->万维网服务->通用HTTP功能-> HTTP重定向

  2. 修改您的 web.config 使用以下代码

 < system.webServer> 
< modules runAllManagedModulesForAllRequests = true>
<删除名称= UrlRoutingModule />
< add name = UrlRoutingModule
type = System.Web.Routing.UrlRoutingModule,System.Web,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a />
< / modules>
< handlers>
< add name = UrlRoutingHandler
preCondition = integratedMode
verb = *
path = UrlRouting.axd
type = System。 Web.HttpForbiddenHandler,System.Web,版本= 2.0.0.0,文化=中性,PublicKeyToken = b03f5f7f11d50a3a />
< / handlers>
< /system.webServer>

3。在您的 global.asax 文件中创建路由


注意:您必须设置应用程序池到 Asp.net 4.0应用程序池,因为路由不适用于 Asp.net 4.0经典应用程序池。


希望这会有所帮助。


I have implemented URL routing in ASP.NET 4.0 using following route.

routes.MapPageRoute(
   "NewsDetails",               // Route name
   "news/{i}/{*n}",  // Route URL
   "~/newsdetails.aspx"      // Web page to handle route
    );

which gives me url like

http://www.mysie.com/news/1/this-is-test-news

and this is working in my localhost fine.

But when I uploaded it on the server it gives ...

Server Error

404 - File or directory not found.
The resource you are looking for might have been removed, had its name changed, 
or is temporarily unavailable.

If I try http://www.mysie.com/news/1/this-is-test-news.aspx then it displays page.

Has anyone have same problem?

How can i set URL http://www.mysie.com/news/1/this-is-test-news to work on windows server 2008 ?

解决方案

To enable default ASP.Net 4.0 routing with IIS 7.5:

  1. Make sure that you have installed the HTTP Redirection feature It can be done -> Control Panel -> Progams -> Turn off windows features -> World wide web Services -> Common HTTP Features -> HTTP Redirection
  2. Modify your web.config with the code below

 

<system.webServer>   
    <modules runAllManagedModulesForAllRequests="true">    
        <remove name="UrlRoutingModule"/>
        <add name="UrlRoutingModule" 
             type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </modules>
    <handlers>
        <add name="UrlRoutingHandler" 
             preCondition="integratedMode" 
             verb="*" 
             path="UrlRouting.axd" 
             type="System.Web.HttpForbiddenHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
    </handlers>
</system.webServer>

3. Create Routes in your global.asax file

Note: You have to set Application Pool to Asp.net 4.0 application pool , as routing is not working with Asp.net 4.0 Classic Application pool.

Hope this will help.

这篇关于ASP.NET 4.0 URL路由HTTP错误404.0-找不到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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