Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/291.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/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
C# 包括;www";在网站改变一切?_C#_Asp.net_Redirect - Fatal编程技术网

C# 包括;www";在网站改变一切?

C# 包括;www";在网站改变一切?,c#,asp.net,redirect,C#,Asp.net,Redirect,我见过像谷歌和facebook这样的网站从“facebook.com”或“www.facebook.com”重定向到他们网站的“”版本。当人们第一次访问我的网站时,我怎么能这样重定向 这是我目前的代码: var link = HttpContext.Current.Request.Url.AbsoluteUri.ToLower(); var path = HttpContext.Current.Request.Url.AbsolutePath; if (link.StartsWith("http

我见过像谷歌和facebook这样的网站从“facebook.com”或“www.facebook.com”重定向到他们网站的“”版本。当人们第一次访问我的网站时,我怎么能这样重定向

这是我目前的代码:

var link = HttpContext.Current.Request.Url.AbsoluteUri.ToLower();
var path = HttpContext.Current.Request.Url.AbsolutePath;
if (link.StartsWith("http://www") == false)
{
Response.Redirect("http://www.arcadeLegend.com" + path);
}
我用这个

<rule name="Redirect to www" patternSyntax="Wildcard" stopProcessing="true">              
<match url="*" />
    <conditions>
            <add input="{HTTP_HOST}" pattern="domain.com" />
     </conditions>
 <action type="Redirect" url="http://www.domain.com/{R:0}" />
 </rule>

<rule name="HTTP Redirect to HTTPS" enabled="true" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<conditions>
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://www.domain.com/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>


.

太棒了!我只是把它添加到web.config?很好!