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.com or http://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!