Permission in website - c#

i am developing a small project in my localhost.
But i am a little problem, i have this ;
<system.web>
<authentication mode="Forms">
<forms loginUrl="Login.aspx"/>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
<location path="RecoverPassword.aspx">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
but when i go to login.aspx (i have a link to go to RecoverPassword), and when i click it always go to login.aspx.
What i am doing wrong?

Looks to me like you're doing it right. Only thing I'd guess is that somewhere you've misspelled something - try double-checking that the link really takes you to RecoverPassword.aspx.

Related

C# Anonymous User Authorization Failure

I am trying to set up a forms authentication application where all pages are accessible to authenticated users with the exception of the login page which is open to all or anonymous users.
I set up web.config like below:
<system.web>
<authentication mode="Forms">
<forms name=".ADAuthCookie" loginUrl="~/Login.aspx" timeout="3"/>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
...
</system.web>
....
<location path="Login.aspx">
<system.web>
<authorization>
<allow users="?"/>
<!-- also tried this
<allow users="*"/>
-->
</authorization>
</system.web>
</location>
I also set the start page (in VS 2019) to login.aspx. When I run it I still get:
Description: An error occurred while accessing the resources required to serve this request. The server may not be configured for access to the requested URL.
Error message 401.2.: Unauthorized: Logon failed due to server configuration. Verify that you have permission to view this directory or page based on the credentials you supplied and the authentication methods enabled on the Web server.
I solved the problem by moving login.aspx to a folder (I called it Account). I added a web.config in this folder with content:
<?xml version="1.0"?>
<configuration>
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</configuration>
I removed the "location" part from main web.config. So it looks like:
<system.web>
<authentication mode="Forms">
<forms name=".ADAuthCookie" loginUrl="~/Account/Login.aspx" timeout="3"/>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
....
</system.web>

MvcCaptcha image does not appear if authentication is turned on

SSB.Web.Mvc.MvcCaptcha
The image does not appear if a form authentication is turned on
in the web.config file:
<authorization>
<deny users="?" />
</authorization>
Then the image does not appear
How I fix that ?
the plug in is SSB.Web.Mvc.MvcCaptcha
from http://www.smartsoftwarebits.com/mvccaptcha
Add following section to the web.config <configuration> section to authorize anonymous access to the MvcCaptcha controller.
<location path="MvcCaptcha">
<system.web>
<authorization>
<allow users="?"/>
</authorization>
</system.web>
</location>

Authentication in web.config causes all my assets to be unreachable

In my web.config I have this authentication setting:
<authentication mode="Forms">
<forms loginUrl="login.aspx" name="signin" path="/" protection="All" timeout="525600">
</forms>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
For some reason, if I comment it out I can see my website just perfectly with all the assets (js, css, images), but if I uncomment it, none of the assets can be reached, instead it just redirects to login page.
here is a nice in-depth article for you. basically, it says you can configure this in your web.config by adding <location> blocks like so:
<!-- file level access -->
<location path="default1.aspx">
<system.web>
<authorization>
<allow users ="*" />
</authorization>
</system.web>
</location>
<!-- folder access (and its contents) -->
<location path="subdir1">
<system.web>
<authorization>
<allow users ="*" />
</authorization>
</system.web>
</location>
</configuration>
from this KB article and a bit more info here.
Use Location element.
<location path="~/css">
<system.web>
<authorization>
<allow users="?"/>
</authorization>
</system.web>
</location>
Looks like assets are served via ASP.NET pipeline. Check the following topic:
Prevent IIS from serving static files through ASP.NET pipeline
The
deny users="?"
is saying that no unauthenticated users can access the site at the root and it will redirect to the login page. I normally always keep the root (/) public (allow users="*") and have protected folders set up using the location. That will keep images, css and script folders under the root available for public access.
This should probably work for you if you can move your protected pages into another folder easily:
<configuration>
<system.web>
<authentication mode="Forms">
<forms loginUrl="login.aspx" name="signin" path="/" protection="All" timeout="525600">
</forms>
</authentication>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
<location path="protected">
<authorization>
<deny users="?" />
</authorization>
</location>
</configuration>

deny anonymous for all pages except the "~/" path in asp.net

in asp.net, i use this config section to deny anonymous users for all pages.
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>
<authorization>
<deny users="?" />
</authorization>
and i use the following to declare an exception that anonymous can access.
<location path="Welcome.aspx">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
that works fine for me.
however, how can i set only the default page as an exception?
(such as: anonymous can access only http://mysite/, but can NOT access any other pages in the site?)
i'v tried use location path="~/" or "/" and it doesn't work.
If path="Default.aspx" doesn't work then it cannot be done using configuration. There's no syntax available to specify only the application root in the path attribute.
I think you can change your folder structre to achieve this. Then you can change the web.config to deny user
<configuration>
<system.web>
<authorization>
<allow roles="administrators" />
<deny users="?" />
</authorization>
</system.web>
</configuration>

Using ASP.NET Forms Authentication, how do I get an image to appear on the login screen?

I am doing simple forms authentication for a small ASP.NET (3.5, C#) application and setting up my usernames and passwords in the web.config.
I would like to apply the default stylesheet and include the header graphic (included on every other page) but the graphic and stylesheet won't apply, presumably because the anonymous user doesn't have access to those two files. Is there some easy way for me to add them or some other way to make the image appear on the page?
Here is the relevent section of the web.config:
<authentication mode="Forms">
<forms name=".ASPXFORMSAUTH"
path="/"
loginUrl="login.aspx"
protection="All" timeout="30">
<credentials passwordFormat="SHA1">
<user
name="testuser"
password="hashgoeshere"/>
</credentials>
</forms>
</authentication>
<authorization>
<deny users="?" />
</authorization>
The stylesheet is at:
/stylesheet.css
and the image is at:
/img/logoimage.png
Thanks. This site makes me happy because hopefully it will make Experts Exchange and their lame paywall DIE!
You can add exceptions in your Web.Config using location-specific rules (add these after the System.Web section):
<location path="stylesheet.css">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
<location path="img/">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>

Categories

Resources