在通用处理程序页中使用asp.net获取域名

在通用处理程序页中使用asp.net获取域名,asp.net,vb.net,Asp.net,Vb.net,我想获取不用于远程ip的域名。我有两个域名(网站)。例如www.a1.com和www.a2.com。在a2域中,向a1域的页面发送请求,如GetRequest.ashx http请求的示例是 http://www.a1.com/GetRequest.ashx?username=bala&password=123456 在我的GetRequest.ashx页面中,示例编码 <%@ WebHandler Language="VB" Class="Handler" %> Imp

我想获取不用于远程ip的域名。我有两个域名(网站)。例如www.a1.com和www.a2.com。在a2域中,向a1域的页面发送请求,如GetRequest.ashx

http请求的示例是

http://www.a1.com/GetRequest.ashx?username=bala&password=123456
在我的GetRequest.ashx页面中,示例编码

<%@ 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

          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**

   End Sub

   Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
       Get
         Return False
      End Get
  End Property
End Class
变量域包含www.a1.com,但我需要www.a2.com


使用谷歌分析api解决我的问题?那么如何使用这个api,任何人都可以解释
Page.Request.Url.Host
包含Url的主机名(
www.a1.com
,在您的示例中)

如果
www.a2.com
站点上的请求调用
www.a1.com
站点上的页面,则主机名将始终为
www.a1.com
,因为该主机用于调用该页面。如果您需要知道请求来自
www.a2.com

请检查推荐人,我建议您传递查询字符串变量:

HttpContext.Current.Request.UrlReferrer.Host
在代码中:

   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

您可以通过HttpContext访问请求对象,如下所示:

编辑:更改为获取引用URL的主机名

string host = HttpContext.Current.Request.UrlReferrer.Host;
编辑:URLreferer返回空值。使用HTTP_REFERER的备选方案:

if (!String.IsNullOrEmpty(Request.ServerVariables["HTTP_REFERER"]))
{
    Uri referringUrl = new Uri(Request.ServerVariables["HTTP_REFERER"]);
    string referringHostName = referringUrl .Host;
}

我需要谁发送请求。不是我的网站名,我需要www.a2.comwww.a2.com向www.a1.com发送请求,所以我需要www.a2.com名称ok.ok,但出于安全原因,我需要检查一下。当我使用domainname作为参数时,意味着其他用户也向我的站点发送相同的请求。如何检查请求是否最初发送给我的客户端?您可以检查HTTP Referer(
request.urlReferer
)。假设您正在使用
HttpWebRequest
调用另一个url,您可以将
referer
属性设置为您的www.a2.com url。抱歉,这也是返回我的本地域名www.a1.com,但我需要请求发送方域名www.a2.com出现以下错误“对象引用未设置为对象的实例”@巴拉昌德兰·库马尔:见编辑后的答案。看看这是否会产生更好的结果empty@Balachandran库马尔:可以用服务器直接转到这个页面吗?用传输代替?如果你一开始就找不到推荐人,你就无能为力了。有什么错误吗?您可能应该检查UrlReferer是否为null。未设置为ObjectUrlReferer实例的对象引用不是httpcontextDim域的成员,因为String=context.Request.UrlReferer.Host这还返回一个错误对象引用未设置为object@bala应为“Dim域作为字符串=HTTPContext.Current.Request.UrlReferer.Host'请告诉我,您确实在通过网络传递纯文本用户名/密码。很好。我担心所有的人都会因此而痛打你:)
if (!String.IsNullOrEmpty(Request.ServerVariables["HTTP_REFERER"]))
{
    Uri referringUrl = new Uri(Request.ServerVariables["HTTP_REFERER"]);
    string referringHostName = referringUrl .Host;
}