how to check if i am at localhost in global.asax

  • Thread starter Thread starter Eirik Eldorsen
  • Start date Start date
E

Eirik Eldorsen

I have a webpage that starts a thread on Application_Start in global.asax. I
don't want to start start this thread when I am testing the application at
localhost. How can I check if I am at localhost when I don't have a Request
object?


Eirik
 
I have a webpage that starts a thread on Application_Start in global.asax. I
don't want to start start this thread when I am testing the application at
localhost. How can I check if I am at localhost when I don't have a Request
object?

Eirik

HttpApplication.Request.Url.Host
 
Thank you for answering. But this doesn't seem to work:

void Application_Start(object sender, EventArgs e)
{
HttpApplication http = new HttpApplication();
if (http.Request.IsLocal)
// do nothing
else
{
MyThread myThread = new MyThread();
}
}

This code throws this exception:
[HttpException (0x80004005): Request is not available in this context]
System.Web.HttpApplication.get_Request() +3302041
ASP.global_asax.Application_Start(Object sender, EventArgs e) +28
 
I figured out how to do it now! Server.MachineName is always available.



Eirik Eldorsen said:
Thank you for answering. But this doesn't seem to work:

void Application_Start(object sender, EventArgs e)
{
HttpApplication http = new HttpApplication();
if (http.Request.IsLocal)
// do nothing
else
{
MyThread myThread = new MyThread();
}
}

This code throws this exception:
[HttpException (0x80004005): Request is not available in this context]
System.Web.HttpApplication.get_Request() +3302041
ASP.global_asax.Application_Start(Object sender, EventArgs e) +28

Alexey Smirnov said:
HttpApplication.Request.Url.Host
 
Eirik said:
Thank you for answering. But this doesn't seem to work:

void Application_Start(object sender, EventArgs e)
{
HttpApplication http = new HttpApplication();
if (http.Request.IsLocal)
// do nothing
else
{
MyThread myThread = new MyThread();
}
}

This code throws this exception:
[HttpException (0x80004005): Request is not available in this context]
System.Web.HttpApplication.get_Request() +3302041
ASP.global_asax.Application_Start(Object sender, EventArgs e) +28

Refer to the existing application instead of creating new one.

void Application_Start(object sender, EventArgs e)
{
if (!System.Web.HttpContext.Current.Request.IsLocal)
{
MyThread myThread = new MyThread();
}
}
 
Thank you for answering. But this doesn't seem to work:

void Application_Start(object sender, EventArgs e)
{
HttpApplication http = new HttpApplication();
if (http.Request.IsLocal)
// do nothing
else
{
MyThread myThread = new MyThread();

}
}

This code throws this exception:
[HttpException (0x80004005): Request is not available in this context]
System.Web.HttpApplication.get_Request() +3302041
ASP.global_asax.Application_Start(Object sender, EventArgs e) +28

"Alexey Smirnov" <[email protected]> skrev i melding

HttpApplication.Request.Url.Host- Hide quoted text -

- Show quoted text -

Sorry, I'm wrong...
HttpContext.Current.Request.Url.Host.ToLower().ToString() does the name
 
Back
Top