ASP.NET 4.0 URL 路由 HTTP 错误 404.0 - 未找到 [英] ASP.NET 4.0 URL Routing HTTP Error 404.0 - Not Found
问题描述
我已经使用以下路由在 ASP.NET 4.0 中实现了 URL 路由.
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
);
这给了我像
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.
如果我尝试 http://www.mysie.com/news/1/this-is-test-news.aspx 然后它显示页面.
If I try http://www.mysie.com/news/1/this-is-test-news.aspx then it displays page.
有人遇到同样的问题吗?
Has anyone have same problem?
如何设置网址http://www.mysie.com/news/1/this-is-test-news 可以在 windows server 2008 上运行吗?
How can i set URL http://www.mysie.com/news/1/this-is-test-news to work on windows server 2008 ?
推荐答案
使用 IIS 7.5 启用默认的 ASP.Net 4.0 路由:
To enable default ASP.Net 4.0 routing with IIS 7.5:
- 确保您已安装HTTP 重定向功能可以这样做 -> 控制面板 -> 程序 -> 关闭 Windows 功能 -> 万维网服务 -> 常用 HTTP 功能 -> HTTP 重定向
- 使用以下代码修改您的
web.config
- 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
- 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.在 global.asax
文件中创建路由
3. Create Routes in your global.asax
file
注意:您必须将应用程序池设置为 Asp.net 4.0 应用程序池,因为路由不适用于 Asp.net 4.0 经典应用程序池.
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.
希望这会有所帮助.
这篇关于ASP.NET 4.0 URL 路由 HTTP 错误 404.0 - 未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!