[英]%20 in my Url in ASP.Net Mvc
I have such Url: /%20Account/%20LogOn?ReturnUrl=%2f+Admin%2f+Index
我有这样的网址: /%20Account/%20LogOn?ReturnUrl=%2f+Admin%2f+Index
I have two questions:我有两个问题:
1)Why I have %20
before Account
and LogOn
? 1)为什么我在Account
和LogOn
之前有%20
? Is it something like spaces?是不是有点像空格?
2)How to remove %20
before Account
and LogOn
? 2)如何在Account
和LogOn
前删除%20
?
Maybe something wrong with Routes?也许路线有问题?
It's my class RegisterRoutes:这是我的类 RegisterRoutes:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
null,
"",
new { controller = "Product", action = "List",category = (string)null,page=1 }) ;
routes.MapRoute(null,
"Page{page}",
new { controller = "Product", action = "List",category = (string)null });
routes.MapRoute(
null,
"{category}",
new { controller = "Product", action = "List", page = 1 });
routes.MapRoute(
null,
"{category}/Page{page}",
new { controller = "Product", action = "List"});
routes.MapRoute(null, " {controller}/ {action}");
}
Because your url contains white space between words,因为您的网址包含单词之间的空格,
For example when you enter this (' somesite.com/some thing ') address in your browser, your browser encode that address to 'somesite.com/some%20thing'例如,当您在浏览器中输入此 (' somesite.com/some thing ') 地址时,您的浏览器将该地址编码为'somesite.com/some%20thing'
then to decode your URL
in code behind, you can use Server.UrlDecode("someURL")
然后在后面的代码中解码你的URL
,你可以使用Server.UrlDecode("someURL")
1)Why I have %20 before Account and LogOn? 1)为什么我在帐户和登录之前有 %20? Is it something like spaces?是不是有点像空格?
This is because you have space inside the URL string.这是因为 URL 字符串中有空格。 Those are converted into encoded string which for the same is %20那些被转换成编码字符串,同样是 %20
2)How to remove %20 before Account and LogOn? 2)如何在帐户和登录前删除 %20?
You need to create a link without a space before Account and LogOn.您需要在帐户和登录前创建一个没有空格的链接。 If you are using Html Helper to create the link, you may have not noticed a space before the string of the action.如果您使用 Html Helper 创建链接,您可能没有注意到操作字符串前有一个空格。
1) That is the encoded URL
. 1) 那是编码的URL
。
2) Not sure in what context you are using it but you can decode it using Server.UrlDecode("string")
2)不确定您在什么上下文中使用它,但您可以使用Server.UrlDecode("string")
对其进行解码
I had a similar problem in my application, where %20 appears at the end of the url.我在我的应用程序中遇到了类似的问题,其中 %20 出现在 url 的末尾。 I had to use .Trim() in order to remove the space before I pass in the required id.在传入所需的 id 之前,我必须使用 .Trim() 来删除空格。
@Html.ActionLink("Details", "Details", new { id = item.ID_NO.Trim()})
and that solved my problem.这解决了我的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.