1

I have an ASP.NET Application deployed to IIS, application will be called from another separate website(Java based application which is like a portal), Can I find the URL of the that website (Java based application )from where the request came to my asp.net application ?

The reason why I need that requested URL is that in my application I have a HOME button when clicked should redirect the USER to the website(Java based application) from where my asp.net application is called. I can't hard code the URL as the request will come from multiple places (as that java based website is in multiple servers with different or same domain names).

msbyuva
  • 3,467
  • 13
  • 63
  • 87
  • 3
    *If* its available it will be in the Referrer: [Getting the HTTP Referrer in ASP.NET](http://stackoverflow.com/questions/4258217/getting-the-http-referrer-in-asp-net) Or use JavaScript; `window.history.go(-1)` – Alex K. Jul 07 '14 at 16:09

1 Answers1

4

The most reliable way is probably to have the "home" application provide a "return URL" when it links to your application. Something like:

<a href="http://yourserver/yourapplication?HomeURL=http%3A%2F%2Fhomeserver%2Fhomeapplication

Then in your application you'd check the query string for that value and probably just keep it in session or some transient session-like persistence:

Session["HomeURL"] = Request.QueryString["HomeURL"];

(Or of course something less coupled to the HTTP Context if possible, particularly in an MVC application.)

You can perhaps create a default of some sort of none is provided, maybe linking back just to your application's home or perhaps trying to get the value from Request.UrlReferrer (which isn't always available). Then your "Home" link would be that value, at least for the duration of that user's session (or however long you persist it).

David
  • 208,112
  • 36
  • 198
  • 279
  • Request.Referrer is not available for me in al cases for me. appending ReturnURL will work for me.. thank You.!! – msbyuva Jul 07 '14 at 17:14