asp.net - How do I get the IP address of the current website in global.asax? -
i'd in application_start method, can write 'robots.txt' file if site running on test server.
thanks
i thought old school, using servervariables collection, following worked nicely in test app, running under built in vs web server:
void application_start(object sender, eventargs e) { // code runs on application startup string localaddress = context.request.servervariables["local_addr"]; // returns "::1" when running under vs server, throws // exception under iis express, assume under iis. }
the next best option can come like:
void application_start(object sender, eventargs e) { // code runs on application startup string servername = server.machinename; }
which works on both vs , iis express, if know name of test or live servers, check against instead?
Comments
Post a Comment