4
I am developing a C# MVC3 portal and in a given operation I need to open another portal in a separate window. To open the page of this new portal I need to send some credentials, since this is implemented with basic Authentication.
I would like to know how I can do it. I have tried it on controller
:
var request = (HttpWebRequest)WebRequest.Create(redirectUrl);
request.Method = "GET";
request.UseDefaultCredentials = false;
request.PreAuthenticate = true;
var cred = new NetworkCredential("user1", "pass123");
var cache = new CredentialCache();
cache.Add(new Uri(redirectUrl), "Basic", cred);
request.Credentials = cache;
var response = (HttpWebResponse) request.GetResponse();
return Redirect(response.ResponseUri.ToString());
What’s the best way to do this?
You can’t do that. The best you can do is ask that URI by passing the credentials and returning the answer instead of redirecting.
– Paulo Morgado
cannot set the cookie and then open the page ?
– Elton A. Pering