[英]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类。
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.