简体   繁体   English

像http://example.com这样的输入网址在操作输入中更改为http:/example.com

[英]Input URL like http://example.com changes to http:/example.com in action input

I asked a question to get URL as action input here . 我问了一个问题, 在这里将URL作为动作输入。 Now I have a new problem. 现在我遇到了一个新问题。 The passed URL to action changes from http://example.com to http:/example.com . 传递的操作URL从http://example.com更改为http:/example.com

I want to know why and how can I resolve the problem. 我想知道为什么以及如何解决问题。

PS: I added this code to resolve but I think there may be another problems in future! PS:我添加了这个代码来解决,但我认为将来可能还有其他问题! the code is: 代码是:

if ((url.Contains(":/")) && !(url.Contains("://")))
{
    url = url.Replace(":/", "://");
}

use regex: 使用正则表达式:

string src = @"http://example.com";
string result = Regex.Replace(src, @"(?<=https?:/)/", "");

if you need to revert: 如果你需要恢复:

string src = @"http:/example.com";
string result = Regex.Replace(src, @"(?<=https?:)/(?=[^/])", @"//");

The browser (or server) is replacing a double slash (illegal) with a single one. 浏览器(或服务器)正在用一个替换双斜杠(非法)。
Try it, 试试吧,

http://stackoverflow.com/questions/11853025//input-url-like-http-site-com-changes-to-http-site-com-in-action-input

(in Chrome) goes to: (在Chrome中)转到:

http://stackoverflow.com/questions/11853025/input-url-like-http-site-com-changes-to-http-site-com-in-action-input

If I were you, I would remove the http:// from your path and add it later. 如果我是你,我会从您的路径中删除http://并稍后添加。

http://localhost:1619/Utility/PR/example.com/

Then, url = "http://" + url; 然后, url = "http://" + url;

If you might get secure urls, add that to the route /http/example.com or /https/example.com 如果您可能获得安全网址,请将其添加到路由/http/example.com/https/example.com

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 特殊控制器和动作的自定义mapRoute在MVC中如下所示:http://example.com/someValue - custom mapRoute for special controller and action to be like this in MVC: http://example.com/someValue 如何添加类似于example.com/id的MapRoute - How to add a MapRoute like example.com/id 正则表达式可将URL与替换的通配符进行比较(http://example.com/user/*/profile) - Regex to compare URLs with a wildcard that alternates ( http://example.com/user/*/profile ) 如何使用.net查询https安全网址,如https://example.com/send.aspx?msg=hi - how to query a https secured url with .net like https://example.com/send.aspx?msg=hi 如何将www.example.com重定向到example.com? - How to redirect www.example.com to example.com? 找不到名称为&#39;Address:http://example.com:8123 / blmrg / test_ws / Service1.svc的终结点元素 - Could not find endpoint element with name 'Address:http://example.com:8123/blmrg/test_ws/Service1.svc 当用户仍然看到example.com/1Bta62时,如何将诸如example.com/1Bta62之类的网址重写为example.com/view.aspx?id=1Bta62? - How to rewrite urls such as example.com/1Bta62 to example.com/view.aspx?id=1Bta62 whilst the user still sees example.com/1Bta62? 如何为GET请求的C#规则重写example.com/123重定向到example.com/default.aspx?pid=123和123是动态更改 - How to rewritten rule for c# for GET request example.com/123 redirect to example.com/default.aspx?pid=123 and 123 is dynamic change 路线网址,例如http://www.example.com/{userId} - Route URL such as http://www.example.com/{userId} 在MVC控制器中验证Webhook调用http:// secretkey:12345@www.example.com - Authenticating a webhook call in mvc controller http://secretkey:12345@www.example.com
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM