开发者

ASP.Net get the domain name not the localhost?

I'm trying to write a method which will send an email to client which has a download link that the user can click on to download directly.

Actually I'm emulating it as a continuously running process in Global which keep sending a file to a ftp server, if there is an error with the sending, a link will be sent to admin so that he can download the file directly.

My question is how can I get the external link, for example I would like to have http://w开发者_如何学运维ww.abc.com/temp/file.txt. I want a generic solution so that whatever the domain I change my server too, the code still work?

Thanks


ASP.NET doesn't technically "know" what the entry domains are. All it cares about are applications, which are mostly orthogonal to the authority the user is coming in on. In the context of a request thread, it knows which domain that user probably asked for, but that's all.

You can get the server-relative path by using (among other things) Control.ResolveUrl("~/path_to_file"); - from there, you'll need some config-driven way of determining what the domain should be.


I am not sure that I understand question fully, but on IIS 7 you can get domains (IIS Bindings) defined for some site with Microsoft.Web.Administration assembly

ServerManager sman = new ServerManager();     
foreach (Site iisSite in sman.Sites)
{
  foreach (Binding bind in iisSite.Bindings)
  {
    // bind.Host - here is the site domain
  }

}


0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜