1. JavaScript
A cópia do código é a seguinte:
/**
* Obtenha o referente da solicitação HTTP
* @ishost se deve retornar o host quando o referente booleano estiver vazio (o endereço da página inicial)
*/
função get_http_referer (ishost) {
if (ishost === indefinido) {ishost = true; }
if (document.Referrer) {
retornar document.Referrer;
} outro {
if (ishost) {
retornar window.location.protocol + "//" + window.location.host;
} outro {
retornar "";
}
}
}
2. C#
A cópia do código é a seguinte:
/// <summary>
/// Obtenha o referente de solicitação HTTP
/// </summary>
/// <param name = "ishost"> se deve retornar host quando o referente estiver vazio (o endereço da página inicial) </aman>
/// <lorpns> string </lorpns>
public string getReferer (bool ishost)
{
if (request.urlReferrer! = null)
{
Return request.urlReferrer.toString ();
}
outro
{
se (ishost)
{
Return request.url.scheme + ": //" + request.url.authority;
}
outro
{
retornar "";
}
}
}
3. Obtenha várias partes do URL de solicitação em C#
Site: http: // localhost: 1897/news/press/content.aspx/123? Id = 1#TOC
A cópia do código é a seguinte:
Request.ApplicationPath/
Request.physicalPathd: /projects/solution/web/news/press/content.aspx
System.io.path.getDirectoryName (request.physicalPath) d:/Projects/Solution/Web/News/Press
Request.PhysicalApplicationPathd:/Projects/Solution/Web/
System.io.path.getFilename (request.physicalPath) content.aspx
Request.CurrentexecutionFilePath/News/Press/Content.aspx
Request.FilePath/News/Press/Content.aspx
Request.Path/News/Press/Content.aspx/123
Request.rawurl/news/press/content.aspx/123? Id = 1
Request.url.absolutepath/news/press/content.aspx/123
Request.url.absoluteurihttp: // localhost: 1897/news/press/content.aspx/123? Id = 1
Request.url.schemehttp
Request.url.hostlocalhost
Request.url.port1897
Request.url.AuthorityLocAlHost: 1897
Request.url.localpath/news/press/content.aspx/123
Request.pathinfo/123
Request.url.pathandQuery/news/press/content.aspx/123? Id = 1
Request.url.Query? Id = 1
Request.url.fragment
Request.url.segments/
Notícias/
Imprensa/
Content.aspx/
123
4. Javascript Window.Location Object
//www.vevb.com/article/57407.htm
Que tal? Você aprendeu a obter o referente da página em JavaScript e C#? Se você tiver alguma dúvida, entre em contato comigo.