问题
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.
- Control.ResolveUrl
- Control.ResolveClientUrl
- 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