3

I'm trying to achieve the following:

I'm building an MVC website that will help me to automatically redirect to another site. WebsiteA will call WebsiteB using HttpWebRequest. WebsiteA will send the details of the user through headers (request.headers.add) WebsiteB will handle all the user details and it should not give response to WebsiteA and page should be redirect to requseted page.

WebApplication 1 :


    public ActionResult RedirectPage(string firstName,string lastName)
    {
       var url = "http://localhost:64603/";

        var request = (HttpWebRequest)WebRequest.Create(url);

        request.Headers.Add("firstName", firstName);

        request.AllowAutoRedirect = false;
        var response = (HttpWebResponse)request.GetResponse();

        return new RedirectResult(url);
     }

Web Application 2 :

    public ActionResult Index()
    {
        var re = Request;
        var headers = re.Headers;
        if (Request.Headers["firstName"] != null)
        {
            string ss = Request.Headers["firstName"].ToString();

        }
        ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";

        return View();
    }

So, my requirement is the page should be redirected from WebApplication1 to WebApplication2 and data should be send through headers.

  • When its redirect to another site... that site becomes the parent... if you cant control that site.. then I am struggling to follow... how you are going to change the behavior of the site you redirected to... – Seabizkit Jan 30 '16 at 07:41
  • Actually we will send the controller and action name along with url and send data through headers eg : redirectUrl : "http://localhost:8080/Home/Index" – durga siva kishore mopuru Jan 30 '16 at 07:44
  • Is this a subdomain site or completely different domain. You need to provide that first. – Aizen Jan 30 '16 at 07:45
  • Ok, it makes things easier, now is it a Get or Post... If complicated, PUT etc etc. – Aizen Jan 30 '16 at 07:49
  • what? ok lets get the steps... correct this...; STEP1. Land on site 1 STEP2. click something... re-dircted to site 2. STEP3 not sure... FINISHED. Do you own both site 1 and 2? Please explain in more detail with steps... second guessing what you trying to do will make it very hard to advise. – Seabizkit Jan 30 '16 at 09:24
  • Thanks for the update.... you are getting the result of WebApp2 in WebApp1... if you are not interested in the response of the request then just dont use it? as per the redirect... are you saying that when you call WebApp2 via HttpWebRequest in WebApp1 it is redirecting your orginal call i.e http://localhost:64603/ if so where is it redirecting it to? – Seabizkit Jan 30 '16 at 10:19
  • also the last part in WebApp1 is not making much sense... why are you redirecting to the url you just made a code request via? that doesnt make much sense... – Seabizkit Jan 30 '16 at 10:20
  • is the end result.... that you want to end up on WebApp2 url with the data?... from the header info? – Seabizkit Jan 30 '16 at 10:25
  • sounds like http://stackoverflow.com/questions/18026050/mvc-redirect-with-custom-headers – Seabizkit Jan 30 '16 at 10:28

0 Answers0