How do I stop other domains from pointing to my domain?

前端 未结 7 771
深忆病人
深忆病人 2021-02-08 12:58

I recently found out that there are other domain names pointing to my website (that don\'t belong to me) and I was wondering how people can stop/prevent this from happening. I\'

相关标签:
7条回答
  • 2021-02-08 13:29

    In IIS there is a setting called bindings that allows you to select which hostnames your website will respond to. This feature allows an instance of IIS to host mulitple websites on a single IP address.

    If you want your site to only work for http://example.com/ and http://www.example.com/, you should set the bindings to only work for "example.com" and "www.example.com".

    The exception here is if you are using SSL. If you are, IIS cannot determine the hostname and you will most likely have to use a dedicated IP address for your site. In that scenario, user608576's solution will work. Although, I would put that code in your Global.asax file:

    <%@ Application Language="C#" %>
    <script runat="server">
    void Application_BeginRequest(Object sender, EventArgs args)
    {
        HttpRequest request = HttpContext.Current.Request;
        HttpResponse response = HttpContext.Current.Response;
    
        if( (request.Url.Host != "example.com") && (request.Url.Host != "www.example.com") )
        {
            response.Clear();
            response.Write("Unauthorized domain name: " + request.Url.Host);
            response.End();
        }
    }
    </script>
    
    0 讨论(0)
提交回复
热议问题