0

Am using WebRequest to validate Url before saving it to Db, But for some url's am getting 403 forbidden error. Please suggest me how can i resolve this issue or any alternate way for this.

i have used code like below.

var webRequest = WebRequest.Create(url);
var webResponse = webRequest.GetResponse();

i also tried WebClient in local its working but when we deploy its throwing same error. Please find the WebClient code aswell

 using (WebClient webClient = new WebClient())
 {
    webClient.Headers.Add("user-agent", "test");
    string content = webClient.DownloadString(url);
 }  

The main purpose we are used this to check when user enters any url attacks.. Please suggent if any way to resolve this

Surya
  • 265
  • 1
  • 3
  • 10
  • Sounds to me like the target site expects authentication and accepts integrated Windows Authentication if you run it locally but rejects the user context when deployed. Try running locally in the user context you are using when deployed (Task User, SQL Agent, ?) – Filburt Jul 29 '21 at 07:15
  • Hi @Filburt, Thanks for the input... i tried connecting with VPN... with VPN WebClient is now working in Local... without VPN its working... so do u have any idea how can we fix this.. or is there any alternate way? – Surya Jul 29 '21 at 07:43
  • Maybe check [Create/Connect VPN connection through C#.Net](https://stackoverflow.com/q/7913695/205233) on how to make your process connect via VPN. – Filburt Jul 29 '21 at 10:51

0 Answers0