简体   繁体   中英

How to find from where the Request came to ASP.NET Application?

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).

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM