[英]Remove %20 from url routing in visual studio 2008 C#
how to remove "%20" from url? 如何从URL中删除“%20”?
http://myweb.com/India%20is%20a%20great%20country http://myweb.com/India%20is%20a%20great%20country
i want like below url..... 我想要下面的网址.....
http://myweb.com/India-is-a-great-country http://myweb.com/India-is-a-great-country
below is my code: for url routing. 下面是我的代码:用于url路由。
public class PostRouteHandler : IRouteHandler
{
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
string sub = requestContext.RouteData.Values["sub"] as string;
if (string.IsNullOrEmpty(sub))
return Helpers.GetNotFoundHttpHandler();
else
{
if (sub == null)
return Helpers.GetNotFoundHttpHandler();
else
{
HttpContext.Current.Server.UrlEncode(sub);
return BuildManager.CreateInstanceFromVirtualPath("~/ViewEntry.aspx", typeof(Page)) as Page;
}
}
}
}
public class Helpers
{
public static string FormatProductUrl(string sub)
{
return RouteTable.Routes.GetVirtualPath(null, "View Product", new RouteValueDictionary { { "sub", sub } }).VirtualPath;
}
public static IHttpHandler GetNotFoundHttpHandler()
{
return BuildManager.CreateInstanceFromVirtualPath("~/NotFound.aspx", typeof(Page)) as Page;
}
}
<%@ Application Language="C#" %>
<%@ Import Namespace="System.Web.Routing" %>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
}
void RegisterRoutes(RouteCollection routes)
{
string pathAndQuery = Request.Url.PathAndQuery.ToString().ToLower();
// Register a route for Products/{ProductName}
routes.Add(
"View Product",
new Route("{sub}", new WebApplication1.PostRouteHandler())
);
}
and below is the link: 下面是链接:
<h3 style=" padding-bottom:7px"> <asp:HyperLink runat="server" ID="lnkProduct"
NavigateUrl='<%# Helpers.FormatProductUrl(Eval("sub").ToString()) %>' Text='<%# Eval("sub") %>'>
</asp:HyperLink> </h3>
i am using 3.5 version visual studio 2008... 我正在使用3.5版本的Visual Studio 2008 ...
Use HttpContext.Current.Server.UrlDecode(sub);
使用HttpContext.Current.Server.UrlDecode(sub);
for the same. 对于相同的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.