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

ぃ、小莉子 提交于 2019-12-06 05:00:31

问题


I know ASP.NET does this automatically, but for some reason I can't seem to find the method.

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. I just want the full URL.

Can anyone help me out?


回答1:


For the "/#{path}/Default.aspx" part, use:

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

If you need more:

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



回答2:


In a web control, the method is ResolveUrl("~/Default.aspx")




回答3:


Take a look at the VirtualPathUtility class.




回答4:


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
  2. Control.ResolveClientUrl
  3. VirtualPathUtility.ToAbsolute



回答5:


Here's what I use:

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



回答6:


Here's an article that explains the difference between the various ways to resolving paths in ASP.NET -

Different approaches for resolving URLs in ASP.NET



来源:https://stackoverflow.com/questions/777944/how-to-convert-default-aspx-to-http-www-website-com-default-aspx-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!