Category Archives: asp.net-core-mvc

.htaccess equivalent in .NetCore

To allow video to be played in element from my website, but not allowing it through direct link, I created .htaccess in a sub-directory with the source videos, and nothing else. with the below code:

RewriteEngine On
RewriteCond %{REQUEST_URI} \.(mp4|mp3|avi)$ [NC]
RewriteCond %{HTTP_REFERER} !^http://sample.com/.*$ [NC]
RewriteRule ^.* - [F,L]

I need to do the same with .NetCore server, but do not know how?

Any help. thanks.

Why does my iis url rewrite rule not work

I am trying to craft a rewrite rule to rewrite a Web Forms Request

ourdomain.com/Members/Unlock.aspx?&Version=9.07.32&ComputerName=THING&RegistrationID=30424-59920-80950&Cals=4.

To MVC-Core

ourdomain.com/Unlock?&Version=9.07.32&ComputerName=THING&RegistrationID=30424-59920-80950&Cals=4

I have created the rewrite rule

    <rule name="Unlock" patternSyntax="ECMAScript" stopProcessing="true">
      <match url="Members/Unlock.aspx" />
      <conditions>
        <add input="{QUERY_STRING}" pattern="contentID=([^&amp;]+)" />
      </conditions>
      <action type="Redirect" url="Unlock" redirectType="Found" appendQueryString="True" />
    </rule>

But the URL does not rewrite. I guess I'm not matching the correct pattern. The MVC Unlock controller action signature is

    [HttpGet]
    public IActionResult Index(string version, string computerName, string registrationId, int CALs, string message = null)