简体   繁体   中英

HttpWebRequest dynamic url

I am using 2 web servers for my development, 1 publish server and other one is for debugging. They dont have same urls.

I want to make a HttpWebRequest which works on both machines depending which server the code is on. My VS2010 project isnt a web application, so I dont have access to http context.

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(rootofwebserver + "/webservices/someservice.asmx/someoperation"); 

This is what I want.

Is this possible?

Use AppSettings element to setup your url:

<appSettings>
   <add key="WebRequestUrl" value="..." />
</appSettings>

Then in your code you can do:

string webRequestUrl = ConfigurationManager.AppSettings["WebRequestUrl"];

You can create .txt file and store your url and read again if you need. This is a simple way that i think.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM