Open curlyfro opened 6 years ago
i need to create a serverside mvc route to dynamically create and serve PDFs. in mvc 5 i'd define my rewrite rules in web.config. how do you do this is .netcore v2, particularly this project?
Just create a file rewrite-rules.xml
in the root directory.
Edit startup.cs to include:
using Microsoft.AspNetCore.Rewrite;
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
...
app.UseRewriter(new RewriteOptions().AddIISUrlRewrite(env.ContentRootFileProvider, "rewrite-rules.xml"));
}
And your rewrite-rules.xml should look like this:
<rewrite>
<rules>
<clear />
<rule name="Redirect to https" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}?{QUERY_STRING}" redirectType="Permanent" appendQueryString="false" />
</rule>
</rules>
</rewrite>
does anyone know how to setup rewrite rules?