Link to home
Start Free TrialLog in
Avatar of mikha
mikhaFlag for United States of America

asked on

set up a proxy page in asp.net web application

I have an asp.net web application and another internal asp.net website (not open to public) deployed as a rest service.
I want to create a proxy page in my public asp.net application , such that, say
(example contrived for the questions)

when a get request is made with a url parameter -- > http://ck.com/myproxypage.aspx?queryparameter=somevalue,
depending upon the queryparameter, i call internal rest api,  and forward the response to the caller.

the response from the api, could be one file, or multiple files such as html, js and css files. it can be just a pdf file .
how would i get the response from api and forward all the content to the caller?
Avatar of Mrunal
Mrunal
Flag of India image

Hi
You can write your own logic in code behind of myproxypage.aspx page.

Read querystring parameter and accordingly call respective REST Api.

Read this before implementation:
https://www.serviceobjects.com/blog/path-and-query-string-parameter-calls-to-a-restful-web-service/


Now of you want to respond back to user/client with some file then below are some options:

https://www.c-sharpcorner.com/article/sending-files-from-web-api/

https://stackoverflow.com/questions/11125535/how-to-return-a-file-using-web-api

If multiple files are to be returned then better way is return in zip format.
e.g.
https://www.aspsnippets.com/Articles/Download-multiple-files-at-once-in-one-HTTP-Request-in-ASPNet-using-C-and-VBNet.aspx

Hope this helps you.
Avatar of mikha

ASKER

@Mrunal  - thanks for your comment. one thing I'm not clear is ,  

if a client makes a request to my proxy page and depending on that incoming request, i make a call to my internal api.

say the result is a html page, a javascript file and a css file.

now how do i write them back to the client, so that they can see the html with the required javascript and css file .
so in other words, to simulate client making a call directly to the api, and getting a well formatted web page back.

i don't think , if we zip all those and write back, they will see the html with correct styling, will they?
Hi CK,
So you want to send HTML page (including js and css) to client.

Have you deployed that HTML page (including js and css) somewhere?

If yes, then you can share that link to client and that's it.

If not, then again two options:
Either you have to deploy (if this suites in your architecture and security concerns) that HTML page (including js and css) and share link
OR refer below options:

https://stackoverflow.com/questions/26822277/return-html-from-asp-net-web-api

https://stackoverflow.com/questions/38105305/how-to-return-html-page-from-webapi-action/38106167
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.