在asp.net中重写查询字符串的URL? [英] URL Rewriting in asp.net for a query string ?
问题描述
大家好,
我的Web应用程序中包含以下URL: http://localhost:50141/NewsDetails.aspx?NewsId = 2 [ ^ ].而2是数据库中新闻的ID.但是我需要是将新闻"标题而不是查询字符串变成这样: http://NewsDetails.aspx/Newstitle [ ^ ].但是我不知道如何.这就是我尝试过的事情:
Hi all ,
I have in my web application the following url : http://localhost:50141/NewsDetails.aspx?NewsId=2[^].And 2 is the id of the news in the database.But what i need is to put the News title instead of the query string to become like this : http://NewsDetails.aspx/Newstitle[^].But i dont know how.And this is what i tried:
if (fullOrigionalpath.Contains("NewsId=2")) {
Context.RewritePath("/NewsTitle");
}
因此,任何人都可以给我一个提示,说明如何放置从数据库中检索到的新闻标题,并放置它而不是其对应的ID吗?
在此先谢谢您.
So please can anyone give me a hint on how to put the news title which is retrieved from database and put it instead of its corresponding id ?
Thanks in advance.
推荐答案
检查下面的链接.
http://weblogs.asp. net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx [此处 [
Check the below link.
http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx[^]
More links here[^].
在此处 [
Download the zip file here[^] it has the dll and the documentation. The link is mentioned in ScottGu blog as well.
您似乎正在使用ASP.Net 4.0,因此不要使用URL rewriting
而是使用URL Routing
.
因此,为每个动态数据动态添加另一个Route
.
请参见下面的链接使用ASP.NET 4.0进行URL路由 [网址路由 [ ^ ]
It looks like you are using ASP.Net 4.0 so instead of usingURL rewriting
useURL Routing
.
So for every dynamic data add anotherRoute
dynamically.
See below links URL Routing with ASP.NET 4.0[^], Url Routing[^]
这篇关于在asp.net中重写查询字符串的URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!