Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 使用子域从www重定向到非www_Asp.net_C# 4.0 - Fatal编程技术网

Asp.net 使用子域从www重定向到非www

Asp.net 使用子域从www重定向到非www,asp.net,c#-4.0,Asp.net,C# 4.0,当用户输入带有子域的URL时,我需要将URL从www重定向到非www 例如: www.abc.xyz.com至abc.xyz.com string url = Request["HTTP_REQUEST_URL"]; // not sure the exact Constant name of the header Uri uri = new Uri(url); if(uri.Host.StartsWith("www.") && uri.Host.Count(c => (

当用户输入带有子域的URL时,我需要将URL从www重定向到非www

例如:

www.abc.xyz.com至abc.xyz.com

string url = Request["HTTP_REQUEST_URL"];  // not sure the exact Constant name of the header
Uri uri = new Uri(url);
if(uri.Host.StartsWith("www.") && uri.Host.Count(c => (c == '.'))>2)
{
    Response.Redirect(url.Replace("www.", ""));
}
正如之前所说的,我认为这是多余的,因为浏览器会为您执行此检查。。。
你真的应该避免为了自己的利益而太聪明。

你为什么要这么做?大多数浏览器都会自动添加后缀,你的问题是什么?你试过什么?这是在使用IIS吗?请提供更多信息/研究证明。你想做什么?@RogerLipscombe:如果用户输入一个像www.abc.xyz.com这样的url,它会显示安全错误。当像abc.xyz这样的url时,同样的thng会完美工作。com@Backtrack:如果用户输入像www.abc.xyz.com这样的url,则会显示安全性错误。当输入像abc.xyz.com这样的url时,相同的thng也能正常工作