简体   繁体   English

如何将“〜/ default.aspx”转换为“http://www.website.com/default.aspx”C#?

[英]How to Convert “~/default.aspx” to “http://www.website.com/default.aspx” C#?

I know ASP.NET does this automatically, but for some reason I can't seem to find the method. 我知道ASP.NET会自动执行此操作,但由于某种原因,我似乎无法找到该方法。

Help anyone? 帮助任何人? Just as the title says. 正如标题所说。

If I do a Response.Redirect("~/Default.aspx"), it works, but I don't want to redirect the site. 如果我执行Response.Redirect(“〜/ Default.aspx”),它可以工作,但我不想重定向该站点。 I just want the full URL. 我只想要完整的URL。

Can anyone help me out? 谁能帮我吗?

For the "/#{path}/Default.aspx" part, use: 对于“/#{path}/Default.aspx”部分,请使用:

Page.ResolveUrl("~/Default.aspx")

If you need more: 如果您需要更多:

Request.Url.Scheme + "://" + Request.Url.Host + ":" + Request.Url.Port

在Web控件中,方法是ResolveUrl("~/Default.aspx")

看一下VirtualPathUtility类。

There are at least three ways of doing this. 至少有三种方法可以做到这一点。 I asked if there was any difference, but I didn't get any answer. 是否有任何不同,但我没有得到任何答案。

  1. Control.ResolveUrl Control.ResolveUrl
  2. Control.ResolveClientUrl Control.ResolveClientUrl
  3. VirtualPathUtility.ToAbsolute VirtualPathUtility.ToAbsolute

Here's an article that explains the difference between the various ways to resolving paths in ASP.NET - 这篇文章解释了在ASP.NET中解析路径的各种方法之间的区别 -

Different approaches for resolving URLs in ASP.NET 在ASP.NET中解析URL的不同方法

这是我使用的:

Response.Redirect(Response.ApplyAppPathModifier("~/default.aspx"))

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

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