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

2020-02-02 10:11发布

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 default.aspx, they just see http://mysite.com/.

So I've added

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

Which works if user hits mysite.com/default.aspx, but if user hits mysite.com/ - he is still redirected to login page.

I've tried <location path="~"> (does not help) and also <location path="~/">, <location path=""> (site fails completely) and could not make it work.

Any ideas?

10条回答
我欲成王,谁敢阻挡
2楼-- · 2020-02-02 10:39

You can achieve by 2 method

Method 1:

You can set redirect path to http://mysite.com/default.aspx in IIS if any user directly comes to your site.in IIS7 you can do that by clicking on Default Document. Here i attached image for your reference

IIS7 setting to add your default page redirection

Method 2

You can go through this URL ASp.NET Membership to set your web config settings.

Let me know if you need more detail on this.

查看更多
The star\"
3楼-- · 2020-02-02 10:41

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>
查看更多
成全新的幸福
4楼-- · 2020-02-02 10:44

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>
查看更多
啃猪蹄的小仙女
5楼-- · 2020-02-02 10:46

The way we done it in the past was to create a folder for all functionality that requires login and set require auth for that folder. All aspx go to that folder. The root of the site stays open.

查看更多
别忘想泡老子
6楼-- · 2020-02-02 10:46

Use this :

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

It works for me.

查看更多
▲ chillily
7楼-- · 2020-02-02 10:48

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.

查看更多
登录 后发表回答