简体   繁体   中英

How to get current host name and path name on ajax calling c# method in asp.net core

jquery code is

 url: '/Jobseeker/Home/?handler=DetailHome_Jobs',
            type: "POST",

in code behind i am not getting current browser url like

http://localhost:44984/project-administrator-contract-jobs-in-India

i am getting a route url ' http://localhost:44984/Jobseeker/Home/ '.. i face this issue only on ajax call method. code behind code is.

public PartialViewResult OnPostDetailHome_Jobs()
        {

             string url = $"{this.Request.Scheme}://{this.Request.Host}{ this.Request.Path}";
        .
        .
        .
        .
        }

i want to get a current url from ajax call method from code behind

http://localhost:44984/project-administrator-contract-jobs-in-India

For the current page url , you can get it from the referer header in the request like below:

public void OnPostDetailHome_Jobs()
{

    string url= Request.Headers["Referer"].ToString();

}

Result: 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM