Anirudha Gupta
Anirudha Gupta

Reputation: 9289

How to return response from the static file in ASP.NET?

I am looking for a solution in which I need to make all endpoint (which return XML and Json) to return empty response and a status code.

the XML/JSON response is decided on the accept header in the request. For example someone call my api I can simply return the response from the file.

How to do this in web.config. I am looking for writing a code in rewrite/rule which check the accept header and if this is xml return the empty xml file or if it's json simple return the json file.

I want to make my rule to match the particular url constraint. for example it's all started with testing. this will be something like "^testing" (case insensitive).

so anything match with ^testing and xml return static xml, and with json return static json response.

I also want to set status code in web.config so I can track that my app is maintenance mode.

Any idea how to do this in web.config.

Upvotes: 0

Views: 125

Answers (1)

Vladimir
Vladimir

Reputation: 853

You can write an HttpModule that will somehow check that your website is in maintenance mode. in this case, the module will write a required HTML/Json content directly into HttpResponse and end the Response.

Alternatively, configure IIS to achieve this result.

Upvotes: 1

Related Questions