开发者

How to protect asp.net application to run only on specified domain?

开发者 https://www.devze.com 2023-02-16 01:43 出处:网络
I\'m going to publish an asp.net pre-compiled web site on shared hosting account but I don\'t want my code to be copied and able to run on another domain. I need to check domain and if not example开发

I'm going to publish an asp.net pre-compiled web site on shared hosting account but I don't want my code to be copied and able to run on another domain. I need to check domain and if not example开发者_Go百科.com or www.example.com redirect to error page or show error as response.

EDIT: Here is my solution based on given answers

void Application_BeginRequest(object sender, EventArgs e)
{
    string[] safeDomains = new string[] { "localhost",
    "example.com", "www.example.com" };

    if (!((IList)safeDomains).Contains(Request.ServerVariables["SERVER_NAME"]))
    {
        Response.Write("Domain not allowed!");
        Response.End();
    }
}


If the domain is known ahead of time, why not check the SERVER_NAME server variable in your global.asax's Application_BeginRequest handler? If it's not one of your predetermined domains, then kick the request to an error page.

This link shows you the various server variables available and some sample output.

Rick Strahl also has a very good blog post about parsing variables to get all sorts of information about your request. It's a good reference.

Hope this helps!


Check the Request.Url.Host of the incoming request. Does it match? The determined might be able the circumvent this by placing the server on a private network and proxying requests to it, but it's probably the best you can manage.


This blog post demonstrates how the domain name protection for ASP.NET applications can be implemented using professional licensing system.


and maybe check domain with your database on your own server to validate domain with a web service. i mean you can have a table on your master website called 'Websites' and in child website get domain name then with web service check your master database if this domain exist

0

精彩评论

暂无评论...
验证码 换一张
取 消