Hamid Talebi Hamid Talebi - 2 years ago 82
ASP.NET (C#) Question

Redirect a domin to another domain in ASP.NET

I have a website with

two domains
and
one hosting server
that worked fine with this two URL.

domains are
www.jongeshadi.com
and
www.jongeshadi.ir
.

i want when a user typed
www.jongeshadi.ir
redirect to
www.jongeshadi.com
.

i Google it and find some solution such as change web config to :

<rewrite>
<globalRules>
<rule name="Redirects to www.jomgeshadi.com" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^jongeshadi.*(ir|com)$" />
<add input="{HTTP_HOST}" pattern="^(www.)?jonsgeshadi.(ir|com)$" />
<add input="{HTTP_HOST}" pattern="^www.jongeshadi.com$" />
</conditions>
<action type="Redirect" url="http://www.domain.ir/{R:0}" />
</rule>
</globalRules>
</rewrite>


But it doesn't worked.any thing is mistake or is there other solution?

Thank you ...

Answer Source

finally found a solution ,but it is clear that we have other solutions .

<script runat="server" language="c#">
        public void Page_Init(Object Src, EventArgs E)
        {
            switch ((Request.ServerVariables["HTTP_HOST"]).Replace("www.", ""))
            {
                case "jongeshadi.com":
                    Response.Redirect("http://www.jongeshadi.ir");
                    break;
                case "jongshadi.ir":
                    Response.Redirect("http://www.jongeshadi.ir");
                    break;
                case "jongshadi.com":
                    Response.Redirect("http://www.jongeshadi.ir");
                    break;
                default:
                    Response.Redirect("http://www.jongeshadi.ir");
                    break;
            }
        }
    </script>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download