Re: Running and debugging a website on http://www.mysite.com instead of http://localhost




The reason to want to use the whole hostname is not to hardcode it, it
is to test an URL rewriting tool.

Respecting your questions:
I'm using Visual Studio 2003 Professional.
I have compilation debug="true" in my web.config file.
I can manually attach to the process, I know and I did it, but it is
too painfull to do that in every run.
I'm still looking an explanation on why this wouldn't work.

Regards,





offwhite@xxxxxxxxx wrote:
When you are doing this, are you using Visual Studio 2003 or 2005?

Either way the obvious question would be whether or not you have debug
enabled on what Visual Studio recognizes as a remote website.

For ASP.NET 2.0 check the Web.config and make sure you see this...

<compilation debug="true">
</compilation>

Also, what edition of VS are you using? An express release does not
allow remote debugging. If you are at least given the option you must
be using Standard or Pro edition.

Since you are simply talking to your local machine with a hostname
directed locally with your hosts file I will assume you are running
this site on your local IIS installation. If you are running WinXP
that must mean IIS 5.1 which only allows you to have the Default host.
Either way, you want to run "Attach to process" and find the IIS
process. You want the process run as the ASPNET user call
aspnet_wp.exe. For IIS 6 you want w3wp.exe.

I am curious about the reasons for hard-coding the hostname into the
website. Normally you could avoid that. I typically use a utility
class to provide my Urls.

I often copy the following code from website to website. I got some
ideas for this code from the Commerce Starter Kit which has this code
in a couple of classes named SiteConfiguration and Utility in the
App_Code folder.

Using these methods and properties allows me to have the site run
normally as a Virtual Directory on a random port on localhost or on the
production website without any changes.

-- SiteConfiguration.cs

public static string HomeUrl
{
get
{
return Utility.GetRelativeSiteUrl("~/");
}
}

public static string ErrorUrl
{
get
{
return Utility.GetRelativeSiteUrl("~/Error.aspx");
}
}

-- Utility.cs

public static string GetSiteUrl(string url)
{
if (String.IsNullOrEmpty(url))
{
return GetSiteRoot() + "/";
}
if (url.StartsWith("~/"))
{
url = url.Substring(1, url.Length - 1);
}
return GetSiteRoot() + url;
}

public static string GetUrlPath(string url)
{
return HttpContext.Current.Request.MapPath(url);
}

public static string GetRelativeSiteUrl(string url)
{
if (!String.IsNullOrEmpty(url))
{
if (url.StartsWith("~/"))
{
url = url.Substring(1, url.Length - 1);
}
return GetRelativeSiteRoot() + url;
}
return GetRelativeSiteRoot() + "/";
}

public static string GetSiteRoot()
{
string Port =
HttpContext.Current.Request.ServerVariables["SERVER_PORT"];
if (Port == null || Port == "80" || Port == "443")
Port = "";
else
Port = ":" + Port;

string Protocol =
HttpContext.Current.Request.ServerVariables["SERVER_PORT_SECURE"];
if (Protocol == null || Protocol == "0")
Protocol = "http://";;
else
Protocol = "https://";;

string sOut = Protocol +
HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + Port +
HttpContext.Current.Request.ApplicationPath;
return sOut;
}

public static string GetRelativeSiteRoot()
{
return HttpContext.Current.Request.ApplicationPath;
}

Brennan Stehling
http://brennan.offwhite.net/blog/

craigkenisston@xxxxxxxxxxx wrote:
Running and debugging a website on http://www.mysite.com instead of
http://localhost

I need to test and debug a website using the full website name instead
of localhost.

So, I went and modified the hosts file by adding 127.0.0.1
www.mysite.com and I was able to view the website on my machine instead
of the remotely hosted site.

I also went to Visual Studio file projects and replaced all appearances
(2 I think) of "localhost" to "mywebsite.com". After a prompt on Visual
Studio while opening the project I was able to view the project in
Visual Studio, I could modify it and compile it and run it with
ctrl-F5(without debug)

The thing that I can not do, is to run the website in debug mode.
When I press F5 I get the message : "Error while trying to run project:
Unable to start debug on remote web server. You do not have permissions
to debug the server. Verify that you are a member of debugger users on
that server""

I'm running as an Administrator, what else permissions would I need ?
Anyway, I went and added users "ASPNET", "IUSER_LOCALHOST",
"IWAM_LOCALHOST" and any users I saw in the groups manager dialog.
Still, I get the same message...

What am I missing ?

Thanks in advance !

.



Relevant Pages


Loading