none
ASP.NET Web Pages - Restrict download folder for all user except admin RRS feed

  • Allgemeine Diskussion

  • Deutsche Version

    Das ist meine Web.config

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    <system.web>
    <authorization>
    <allow roles="Admin"/>
    <deny users="*"/>
    </authorization>
    </system.web>
    </configuration>

    Anschließend hab ich die Einstellungen der Web.config getestet. Zu beginn als User der Rolle Admin mit diesem User konnte ich die Daten runterladen, was so erstmal richtig ist. Wenn ich nun ein anonymer User oder normaler User bin kann ich die Datei auch herunterladen wenn ich den Link zur Datei kenne dies soll aber nicht so sein.

    Ordnerstruktur des Projekts:

    myCompany/
      ->default.cshtml
      ->upload/
        ->Test.accdb
        ->Test.xlsx
        ->Web.config

    So hatte ich es auch schon versucht:

     myCompany/
          ->default.cshtml
          ->Web.config
          ->upload/
            ->Test.accdb
            ->Test.xlsx

    English Version

    My Web.config looks like:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    <system.web>
    <authorization>
    <allow roles="Admin"/>
    <deny users="*"/>
    </authorization>
    </system.web>
    </configuration>

    Now after these settings it should be like only the users with the admin role could download the files of the root from the web.config. i tested the policies if i am a anonymous user i also could download the data if im knowing the right link. Even if i'm logged in as normal user i can download it.

    The folder structure is like this:

    myCompany/
      ->default.cshtml
      ->upload/
        ->Test.accdb
        ->Test.xlsx
        ->Web.config

    I tried that too:

     myCompany/
          ->default.cshtml
          ->Web.config
          ->upload/
            ->Test.accdb
            ->Test.xlsx


    • Bearbeitet koblenz01 Mittwoch, 8. Februar 2017 09:58
    • Typ geändert Stefan FalzModerator Samstag, 31. März 2018 10:57 Thread inaktiv, keine weitere Aktivität
    Mittwoch, 8. Februar 2017 09:51

Alle Antworten

  • Hi,

    eigentlich sieht die erste Variante richtig aus. Bist Du sicher, dass dir der Browsercache (insbesondere bei Firefox ist das teils schon ein arges Problem) einen Strich durch die Rechnung macht?


    Gruß, Stefan
    Microsoft MVP - Visual Developer ASP/ASP.NET
    http://www.asp-solutions.de/ - Consulting, Development
    http://www.aspnetzone.de/ - ASP.NET Zone, die ASP.NET Community

    Mittwoch, 8. Februar 2017 10:06
    Moderator
  • Hallo,

    und danke für die schnelle Antwort, das ganze wird in Google Chrome getestet.

    In der ersten Version greifen die Richtlinien der Web.config nicht. Denn wenn ich diesen Link Aufrufe (http://localhost:59547/myCompany/upload/Test.xlsx) lädt er die Datei erfolgreich herunter. Obwohl ich nicht mal eingeloggt bin. 

    Jedoch in der zweiten Ausführung greift die Richtlinie so, dass nur der Admin auf die myCompany/default.cshtml zugreifen kann. 

    Es geht mir speziell um die Daten aus dem Upload Ordner die sollen nur für den Admin zu laden sein.

    Mittwoch, 8. Februar 2017 10:29
  • Hi,

    das hatte ich schon so verstanden.

    Poste bitte mal die web.config aus dem Root Ordner. Du hast letztendlich zwei Optionen.

    Entweder Du arbeitest in der Root web.config mit <location path="Upload">...</location>, gibst dort also die separaten Einstellungen für den Upload Ordner an oder Du legst die web.config wie oben von dir angegeben im Ordner selbst ab.

    Falls letzteres bei dir nicht funktioniert, wird evtl. irgendetwas anderes stören. Daher bitte wie geschrieben die Root web.config mal hier posten.


    Gruß, Stefan
    Microsoft MVP - Visual Developer ASP/ASP.NET
    http://www.asp-solutions.de/ - Consulting, Development
    http://www.aspnetzone.de/ - ASP.NET Zone, die ASP.NET Community

    Mittwoch, 8. Februar 2017 10:34
    Moderator
  • Das wäre die Root Web.config:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <configSections>
        <sectionGroup name="dotNetOpenAuth" type="DotNetOpenAuth.Configuration.DotNetOpenAuthSection, DotNetOpenAuth.Core">
          <section name="messaging" type="DotNetOpenAuth.Configuration.MessagingElement, DotNetOpenAuth.Core" requirePermission="false" allowLocation="true" />
          <section name="reporting" type="DotNetOpenAuth.Configuration.ReportingElement, DotNetOpenAuth.Core" requirePermission="false" allowLocation="true" />
          <section name="oauth" type="DotNetOpenAuth.Configuration.OAuthElement, DotNetOpenAuth.OAuth" requirePermission="false" allowLocation="true" />
          <section name="openid" type="DotNetOpenAuth.Configuration.OpenIdElement, DotNetOpenAuth.OpenId" requirePermission="false" allowLocation="true" />
        </sectionGroup>
      </configSections>
      <system.web>
        <globalization fileEncoding="utf-8" requestEncoding="utf-8" responseEncoding="utf-8" culture="en-US" uiCulture="de-DE" />
        <customErrors mode="Off" />
        <compilation debug="true" targetFramework="4.0">
          <assemblies>
            <add assembly="System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
          </assemblies>
        </compilation>
        <authentication mode="Forms">
          <forms name=".ASPXAUTH" loginUrl="~/Account/Login.cshtml" timeout="1440" />
        </authentication>
      </system.web>
      <system.webServer>
        <security>
          <requestFiltering removeServerHeader="true"></requestFiltering>
        </security>
        <httpProtocol>
          <customHeaders>
            <remove name="X-Powered-By" />
          </customHeaders>
        </httpProtocol>
      </system.webServer>
      <system.net>
        <defaultProxy enabled="true" />
        <settings>
          <!-- This setting causes .NET to check certificate revocation lists (CRL) 
    			     before trusting HTTPS certificates.  But this setting tends to not 
    			     be allowed in shared hosting environments. -->
          <!--<servicePointManager checkCertificateRevocationList="true"/>-->
        </settings>
      </system.net>
      <runtime>
        <!-- This prevents the Windows Event Log from frequently logging that HMAC1 is being used (when the other party needs it). -->
        <legacyHMACWarning enabled="0" />
        <!-- When targeting ASP.NET MVC 3, this assemblyBinding makes MVC 1 and 2 references relink
    		     to MVC 3 so libraries such as DotNetOpenAuth that compile against MVC 1 will work with it.
    		<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    			<dependentAssembly>
    				<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
    				<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
    			</dependentAssembly>
    		</assemblyBinding>
    		 -->
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="DotNetOpenAuth.AspNet" publicKeyToken="2780ccd10d57b246" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="DotNetOpenAuth.Core" publicKeyToken="2780ccd10d57b246" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0" />
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
      <dotNetOpenAuth>
        <messaging>
          <untrustedWebRequest>
            <whitelistHosts>
              <!-- Uncomment to enable communication with localhost (should generally not activate in production!) -->
              <!--<add name="localhost" />-->
            </whitelistHosts>
          </untrustedWebRequest>
        </messaging>
        <!-- Allow DotNetOpenAuth to publish usage statistics to library authors to improve the library. -->
        <reporting enabled="true" />
        <!-- This is an optional configuration section where aspects of dotnetopenauth can be customized. -->
        <!-- For a complete set of configuration options see http://www.dotnetopenauth.net/developers/code-snippets/configuration-options/ -->
        <openid>
          <relyingParty>
            <security requireSsl="false">
              <!-- Uncomment the trustedProviders tag if your relying party should only accept positive assertions from a closed set of OpenID Providers. -->
              <!--<trustedProviders rejectAssertionsFromUntrustedProviders="true">
    						<add endpoint="https://www.google.com/accounts/o8/ud" />
    					</trustedProviders>-->
            </security>
            <behaviors>
              <!-- The following OPTIONAL behavior allows RPs to use SREG only, but be compatible
    					     with OPs that use Attribute Exchange (in various formats). -->
              <add type="DotNetOpenAuth.OpenId.RelyingParty.Behaviors.AXFetchAsSregTransform, DotNetOpenAuth.OpenId.RelyingParty" />
            </behaviors>
          </relyingParty>
        </openid>
      </dotNetOpenAuth>
      <uri>
        <!-- The uri section is necessary to turn on .NET 3.5 support for IDN (international domain names),
    		     which is necessary for OpenID urls with unicode characters in the domain/host name.
    		     It is also required to put the Uri class into RFC 3986 escaping mode, which OpenID and OAuth require. -->
        <idn enabled="All" />
        <iriParsing enabled="true" />
      </uri>
      <system.data>
        <DbProviderFactories>
          <remove invariant="System.Data.SqlServerCe.4.0" />
          <add invariant="System.Data.SqlServerCe.4.0" name="Microsoft® SQL Server® Compact 4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
        </DbProviderFactories>
      </system.data>
    </configuration>


    Mittwoch, 8. Februar 2017 10:39