How to determine if the request is coming from a particular windows domain

3k views Asked by At

I am developing a web application with MVC-3

I want to give the users of a particular windows domain some special privileges; therefore I have to determine whether the request is coming from that particular domain.

Please note that I am using Forms authentication.

I know that I can do this by tracking the IP address of the user. But is there a way to directly get the domain name?

For example, if the user is logged in as ADomain\AUsername in a windows machine, is there a way to get ADomain?

2

There are 2 answers

1
Erik Funkenbusch On BEST ANSWER

The answer is, maybe and sometimes. First, only Internet Explorer passes credentials through to the server. Second, the server must be on the same domain as the client, third there can't be any proxies or other things in between. Both computer and client must be on the same network as well.

Even with all that, it still only works sometimes. What version of IIS? If it's IIS7 or greater, then there are other issues where you can't combine forms authentication and windows authentication. If you're using IIS6, then it might be able to be done, but it's a huge pain.

In practice, I wouldn't bother.. it's just too much effort for saving the users from typing in their username and password.

1
Sreekanth P On

You can get domain name using UrlReferrer of the request object.

string Domain Name = Request.UrlReferrer.Host;

Also if you want to check in your application that whether the request is coming from different domain or not then please try to verify the hostname of the URL referrer with the hostname of your own application URL. Please use the below code

(if Request.Url.Host != Request.UrlReferrer.Host)
{
}