如何获取完整的URL地址

时间:2013-06-07 07:42:21

标签: c# asp.net-mvc asp.net-mvc-4

我想在ASp.NET MVC 4中获取完整的URL,例如用户输入了url:

http://localhost:5555/#globalName=MainLines&ItemId=5

当我尝试在Global.asax中获取此网址时,我只获得http://localhost:5555/

protected void Application_BeginRequest(object sender, EventArgs e)
{
    var url = HttpContext.Current.Request.Url;
}

由于

1 个答案:

答案 0 :(得分:13)

那是不可能的。片段(#)后面的部分是从不在HTTP请求中发送到服务器,服务器无法检索它。片段只能通过javascript访问。因此,如果要在服务器上检索此值,则必须使用javascript读取它,然后将其存储在某个隐藏字段中,以便将其发送到服务器。

相关问题