Monday, February 7, 2022

Get Base URL from ASP.NET web project using jQuery

HTML: 

Put this code into the head section:

 <base id="BaseUrl" data-baseurl="@Context.Request.Url.GetLeftPart(UriPartial.Authority)@Url.Content("~/")" />



jQuery:

 <script type="text/javascript">

    var rootUrl;

    $(document).ready(function () {

        rootUrl= $("#BaseUrl").data("baseurl");

    });

</script>

No comments:

Post a Comment