Musa
Musa

Reputation: 583

How to serve static file (json) to a explicit path

I want to add a path mysite.com/_this when a request for this path is called I want to serve the json file that's under Sites/MySite/Content.

The caveat is I cannot implement this via code change. I need a way to implement this setup using the IIS CLI.

I have found the following article https://learn.microsoft.com/en-us/iis/extensions/url-rewrite-module/iis-url-rewriting-and-aspnet-routing, but it's a little cryptic and hard to follow.

Windows: Window Server 2016 (1607)

IIS: 10.0.14393.0

Upvotes: 1

Views: 852

Answers (1)

Jalpa Panchal
Jalpa Panchal

Reputation: 12759

In my opinion, the right solution for your issue is iis URL rewrite module.

If you did not install the url rewrite module you could download from the below link:

URL Rewrite

then add a rule in web.config file:

<rule name="Json Redirect" stopProcessing="true">
   <match url="([\S]+[.](json))" />
   <action type="Rewrite" url="folderpath/{R:1}" />
</rule> 

You can do all these changes in the IIS Manager UI, but if you want to script them, look into the PowerShell IIS cmdlets.

Upvotes: 1

Related Questions