Opening Edge (Chromium) using 'System.Diagnostics.Process' and pass request header to target url

Copper Contributor

Hi,

We need to launch Edge (Chromium) using 'System.Diagnostics.Process' with header to target URL request.
My code is -  Process.Start("microsoft-edge:" + <url>);
Which work and open the Edge with url argument.

How can I pass a request header to the url.

Thanks 

3 Replies

@Kamal1315 In general, you should avoid launching a user's browser using a protocol handler wrapper (like "microsoft-edge:") and should instead just pass the URL (e.g. "https://www.foo/"). This will ensure that the user's default browser opens and handles the link. The default browser is more likely to work correctly vs a browser that is not their default (which might not have correct proxy settings, extensions, VPN, account info, etc).

 

To the other part of your question, no, there's no standard for opening a browser and passing headers or POST body information as a part of the initial request. There are ways to do this in certain browsers (e.g. Internet Explorer using COM invocation) but no reliable cross-browser standard. Instead, there are two possible routes:

 

1. Write a local HTML file that contains a form that automatically submits the desired data to the target server. This will allow sending of POST requests, etc.
2. Write a remote HTML file (e.g. on your server) that contains a form that automatically submits the desired data to the target server. This will allow sending of POST requests, etc.

 

Neither of these approaches is likely to allow you to pass a header to the target, insofar as there's no standard way in the web platform to "Navigate with header". That restriction exists mostly for security reasons.

 

What header do you need to pass, to what service or server? Do you control the service/server? Must the data be in a header vs. a POST body or Query Parameter on the URL?

@Eric_LawrenceThanks Eric for reply.
Please see my comments for your query - 
[What header do you need to pass, to what service or server? Do you control the service/server? Must the data be in a header vs. a POST body or Query Parameter on the URL?] 
=> We need to pass authentication header to our own server's hosted web application.
Authentication details are normally sent via header only, so no post body or query string parameter.

@Kamal1315 Yeah, unfortunately this ("Add a header to a navigation request") isn't a capability present in the web platform. You could write a browser extension that does this, or you'd need to change the server such that it has a mechanism to accept the Auth data from the URL or a POST body.