繁体   English   中英

如何使用 mvc c# 获取当前浏览器 url

[英]How to get current browser url using mvc c#

i want current browser URL (ex: http://localhost:1495/Global/General/SectionSetting) i have tried below code but i am getting API URL (ex: http://localhost:1495/api/Apiname/Functionname)

string sPagePath = System.Web.HttpContext.Current.Request.Url.AbsolutePath;

 String baseUrl = Path.GetDirectoryName(HttpContext.Current.Request.Url.OriginalString);

提前致谢

In client and server disconnected architecture in asp.net Web API 2 I was used HttpContext.Header.Referrer to get the client host information. 这只会为您提供基本的绝对 URL。 浏览器相对路径不包含在其中。

从你的问题我可以理解你需要 ajax 请求的浏览器地址。 一种可能的解决方案是使用 ajax 请求将浏览器当前 url 发送到 api 中。 您可以使用 javascript location获取浏览器完整的 url 。 例如

var absolutePath = window.location;

由于我没有看到您的代码,因此我只是尝试分享我的想法。 让我们看看它是否对您有帮助。 您可以分享您的代码以获得更好的建议或解决方案。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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