How to specify root (/) location in web.config?

前端 未结 10 1070
说谎
说谎 2020-12-08 06:22

How does one specify root location in web.config to allow unauthenticated users access it?

The root location is served by default.aspx, but users normally don\'t see

相关标签:
10条回答
  • 2020-12-08 06:38

    To specify root directory you have to set it outside the location block.

    <configuration> 
      <system.web>
        <authorization>
          <allow users=“*“/>
        </authorization>
      </system.web>
    </configuration>
    

    and then secure your other folder using location block

    <location path=“AccessDenied.aspx“>
        <system.web>
            <authorization>
                <deny users=“?“/>
            </authorization>
        </system.web>
    </location>
    
    0 讨论(0)
  • 2020-12-08 06:44

    only use

    <location path=".">
    <system.web>
      <authorization>
        <allow users="*"/>
      </authorization>
    </system.web>
    

    or don't write path,because the default path is root(.)

    0 讨论(0)
  • 2020-12-08 06:46

    Try this one:

    <system.web>
        <urlMappings enabled="true">
            <add url="~/" mappedUrl="~/default.aspx" />
        </urlMappings>
        <authorization>
            <allow roles="admin"/>
            <deny users="*" />
        </authorization>
    </system.web>
    <location path="Default.aspx">
        <system.web>
            <authorization>
                <allow users="*" />
            </authorization>
        </system.web>
    </location>
    
    0 讨论(0)
  • 2020-12-08 06:46

    If you only want to let unauthenticated users to access default.aspx you can use

      <location path="Default.aspx">
        <system.web>
          <authorization>
            <allow users="*"/>
          </authorization>
        </system.web>
      </location>
    

    before <system.web> and set that page as default in your web server.
    In Visual Studio you can select the page and "Set As Start Page".

    If you want to allow access to all the files in the root you have to create folders where you put your pages which need to be accessed by authenticated users.

    You can create a Secure folder where you can put all your protected pages and change your web.config this way:

      <location path="Secure">
        <system.web>
          <authorization>
            <deny users="?"/>
          </authorization>
        </system.web>
      </location>
    

    removing

        <authorization>
            <deny users="?"/>
        </authorization>
    
    0 讨论(0)
  • 2020-12-08 06:46

    Merk was right!

    I used

    <location path="">
                <system.webServer>
                    <httpRedirect enabled="true" destination="http://www.newpathdestination.com" exactDestination="true" httpResponseStatus="Permanent" />
                </system.webServer>
            </location>
    

    on Windows netserver (don't ask), making sure to put nothing in between the quotes for location path. Redirects a request for the old home page to the new home page.

    0 讨论(0)
  • 2020-12-08 06:48

    You probably use a forms authentification no?

    <authentication mode="Forms">
       <forms loginUrl="~/Default.aspx" />
    </authentication>
    

    This will solve your problem. An alternative is:

      <location path="~/Default.aspx">
        <system.web>
          <authorization>
            <allow users="*"/>
          </authorization>
        </system.web>
      </location>
    
    0 讨论(0)
提交回复
热议问题