Asp.net 域名及;发展时间

Asp.net 域名及;发展时间,asp.net,Asp.net,有没有办法在Win7(甚至win2008)中通过域名开发网站? 我的意思是,在开发时(VS2010),当我按F5时,我看到我的应用程序在一个真实的域名下,比如:[MyDomainName.com],而不是[localhost\ProjectName] 非常感谢您的反馈您应该避免对URL进行硬编码,以便域可以在不破坏代码的情况下进行更改。不要用域信息构建url,只需将它们构建为相对链接(~/pagename.aspx,而不是localhost/project/pagename.aspx),这样,站

有没有办法在Win7(甚至win2008)中通过域名开发网站? 我的意思是,在开发时(VS2010),当我按F5时,我看到我的应用程序在一个真实的域名下,比如:[MyDomainName.com],而不是[localhost\ProjectName]


非常感谢您的反馈

您应该避免对URL进行硬编码,以便域可以在不破坏代码的情况下进行更改。不要用域信息构建url,只需将它们构建为相对链接(~/pagename.aspx,而不是localhost/project/pagename.aspx),这样,站点发布到哪里就不重要了。如果需要为需要完整url的内容构建完整url,可以使用以下代码获取站点的当前位置

Private m_serverName As String = ""

Private Sub WebForm1_InitComplete(sender As Object, e As System.EventArgs) Handles Me.InitComplete

  Dim tempPort As String = Context.Request.ServerVariables("SERVER_PORT").Trim

  If tempPort = "80" Or tempPort = "443" Then
     m_serverName = Context.Request.ServerVariables("SERVER_NAME")
  Else
     m_serverName = String.Format("{0}:{1}", Context.Request.ServerVariables("SERVER_NAME"), tempPort)
  End If

  If Request.IsSecureConnection = True Then
     m_serverName = String.Format("https://{0}", m_serverName)
  Else
     m_serverName = String.Format("http://{0}", m_serverName)
  End If
End Sub
然后,当您需要构建url时,请使用以下内容:

Dim tempUrl As String = String.Format("{0}/pagename.aspx", m_serverName)

你为什么要在域名下这么做?有什么具体原因吗?你必须托管你的域以便它可以解析,除非你将它设置为web服务器,否则你不能使用你的本地系统来解析。