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

asp.netWeb Configasp.net Authorization

asp.net Problem Overview


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?

asp.net Solutions


Solution 1 - asp.net

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>

Solution 2 - asp.net

only use

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

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

Solution 3 - asp.net

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.

Solution 4 - asp.net

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.

Solution 5 - asp.net

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>

Solution 6 - asp.net

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>

Solution 7 - asp.net

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>

Solution 8 - asp.net

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.

Solution 9 - asp.net

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.

Solution 10 - asp.net

If you want to specify the root of the directory, use <location path="" >

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMichael EntinView Question on Stackoverflow
Solution 1 - asp.netAlexey SmolyakovView Answer on Stackoverflow
Solution 2 - asp.netmina morsaliView Answer on Stackoverflow
Solution 3 - asp.netChirag BabariaView Answer on Stackoverflow
Solution 4 - asp.netb0rgView Answer on Stackoverflow
Solution 5 - asp.netDemian FlaviusView Answer on Stackoverflow
Solution 6 - asp.netLeftyXView Answer on Stackoverflow
Solution 7 - asp.netWasaView Answer on Stackoverflow
Solution 8 - asp.netSeyoSView Answer on Stackoverflow
Solution 9 - asp.netDavid PView Answer on Stackoverflow
Solution 10 - asp.netmerkView Answer on Stackoverflow