English 中文(简体)
方案上获得国际空间法研究所服务器
原标题:Programmatically get IIS server URL

Short version:

我怎么能够把我的MVC3项目付诸实施? 我确实希望硬拷贝成为服务器地址。

Long version:

Ive got 三个服务器

  1. Development server
  2. QA server for others to test
  3. Production server

上述服务器中没有一个具有相同的URL。

我的网络项目需要生成载有可点击链接的通知电子邮件。

I know that Request.Url.ToString() will get me the server but if possible, I d rather not spend time processing that string everytime I generate an email.

最佳回答

您可处理<代码>查询。 Url一劳永逸地储存这一结果。 仅能确保你以友好的方式获得这一变量。 我早就在生产过程中利用了这一技术,并且像一个药店一样。

问题回答
HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.ApplicationPath;

你们应该trick

请求。 URI是前进的道路。 如果你真的担心业绩,就说明业绩。 我几乎可以保证取得的成果不好。 如果是,你可以通过请求从头盔中人工阅读。 服务器可使用[“HTTP_HOST”] 请求。 服务器

Not sure if this is what you re after, but I recently had to get the URL of the default website on IIS. It proved to be a real pain, but I managed to get this working code...

    using System.DirectoryServices;
    using System.Diagnostics;

    private string GetDefaultSite()
    {
        using (DirectoryEntry w3svc2 = new DirectoryEntry("IIS://Localhost/W3SVC"))
        {
            foreach (DirectoryEntry de in w3svc2.Children)
            {
                if (de.SchemaClassName == "IIsWebServer" &&
                    de.Properties["ServerComment"].Value.ToString() == "Default Web Site")
                {
                    string binding = de.Properties["ServerBindings"].Value.ToString();

                    string[] split = binding.Split( : );

                    if (split[2] == "") return "http://localhost/";
                    else return "http://" + split[2] + "/";
                }
            }
        }
        return "";
    }

看见Server Variables,你可以找到服务器名称。

这可能是一个很好的选择。

其中一项工作是:

Response.Write Server.MachineName;
Response.Write Request.ServerVariables["LOCAL_ADDR"];

页: 1 Url.GetComponents(UriComponents.SchemeAndServer, UriFormat)。 Uneaïd;。 这将从http....返回服务器名称和港口。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签