Get Domain Name using asp.net in Generic handler page
I want to get domain name not for remote ip. i have two domain(website). example www.a1.com and www.a2.com. in a2 domain send a request to a1 domain's page like GetRequest.ashx
the example of http request is
http://www.a1.com/GetRequest.ashx?username=bala&password=123456
in my GetRequest.ashx page example coding
<%@ WebHandler Language="VB" Class="Handler" %>
Imports System
Imports System.Web
Public Class GetRequest : Implements IHttpHandler
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
c开发者_C百科ontext.Response.ContentType = "text/plain"
Dim username As String = context.Request.QueryString("username")
Dim password As String = context.Request.QueryString("password")
**'//Here i need a coding to get requested domain name that is who send the request to my page**
End Sub
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
i already use the following coding but not solve my problem. because it return ip address. i need domain only not for ip.
context.Request.ServerVariables("REMOTE_ADDR")
context.Request.ServerVariables("REMOTE_HOST")
Dim domain As String
Dim url As Uri = HttpContext.Current.Request.Url
domain = url.AbsoluteUri.Replace(url.PathAndQuery, String.Empty)
the variable domain contain www.a1.com but i need www.a2.com
use google analytics api to solve my problem? then how to use this api can any one explain
Page.Request.Url.Host
contains the host name of the url (www.a1.com
in your example)
If a request on the www.a2.com
site calls a page on the www.a1.com
site, the hostname will always be www.a1.com
since that is the host that was used to call the page. I recommend passing a query string variable if you need to know that the request originated from www.a2.com
.
You can access the request object through HttpContext, like so:
EDIT: Changed to get host name of referring URL
string host = HttpContext.Current.Request.UrlReferrer.Host;
EDIT: UrlReferrer is returning null. Alternative using HTTP_REFERER:
if (!String.IsNullOrEmpty(Request.ServerVariables["HTTP_REFERER"]))
{
Uri referringUrl = new Uri(Request.ServerVariables["HTTP_REFERER"]);
string referringHostName = referringUrl .Host;
}
Check the Referrer:
HttpContext.Current.Request.UrlReferrer.Host
Inside your code:
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
context.Response.ContentType = "text/plain"
Dim username As String = context.Request.QueryString("username")
Dim password As String = context.Request.QueryString("password")
**'//Here i need a coding to get requested domain name that is who send the request to my page**
Dim domain as string = context.Request.UrlReferrer.Host
End Sub
精彩评论