ASP.NET authorization, show browser login dialog - asp.net

I have such section in my web.config to deny access of anonymous users to elmah.axd. Is it possible to make exception and add credentials for admin user to allow that user access protected web page? I would like to display browser authentication dialog and ask user for credentials before accessing elmah.axd url.
<location path="elmah.axd">
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</location>

Here is how to do it.
http://www.xoc.net/works/tips/forms-authentication.asp
By the way browser authentication forms are usually used in intranets with Windows authentication. And not forms authentication.

Yes:
Add this to <system.web>
<authentication mode="Forms">
<forms name=".ASPXAUTH"
loginUrl="Login.aspx"
protection="All"
timeout="30"
path="/"
requireSSL="false"
slidingExpiration="true"
defaultUrl="Login.aspx"
cookieless="UseCookies"
enableCrossAppRedirects="false"/>
</authentication>
It will redirect anonymous users to Login.aspx

Related

Sharing windows authentication accross sites in IIS7/IIS7.5

I have a parent website (developed like 5 yrs before) say (sky) which I host in IIS7/IIS7.5 and configure it to use Form authentication and anonymous authentication. The web.config with entries as follows:
<authentication mode="Forms">
<forms loginUrl="Login.aspx" protection="All" timeout="480" name=".ASPXAUTH" path="/" requireSSL="false" slidingExpiration="true" defaultUrl="~/Home" cookieless="UseDeviceProfile" enableCrossAppRedirects="false" />
</authentication>
<authorization>
<deny users="?" />
</authorization>
<location path="cloud">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
Now I have a child website (developed 2 days ago) say (cloud) which I host under sky and configure it to use Windows authentication and anonymous authentication. Its own web.config has the following entries.
<authentication mode="Windows" />
<authorization>
<deny users="?" />
</authorization>
<identity impersonate="false" />
When I access sky/, I end up on the login form, which is expected. I enter the username/pass and I can browse the parent website absolutely fine.
Unfortunately, when I access sky/cloud/, a username/password prompt box shows up, I enter the correct creds, but it does not authenticate and I cannot browse the child website. It repeatedly throws the creds box.
I switched the priority of authentication provider to do NTLM first over Negotiate on cloud, still no luck.
Why does the new site need to be under the parent site? Gotta blame branding here :(
Any idea's on getting this working would be appreciated.

How to redirect to denial access page when using role based access in ASP.NET?

What are all the ways we can redirect to a page in case of denial of access based on roles?
I can able to get the role based authorization working but I ended up the page redirected to login page always in case of no authorization for one particular role. Please help
<authentication mode="Forms">
<forms name=".ASPXAUTH" loginUrl="~/Login.aspx"
defaultUrl="Unauthorizedaccess.aspx" protection="All" path="/"
requireSSL="false"
cookieless="UseUri" domain=""
enableCrossAppRedirects="false" slidingExpiration="true" timeout="2880"></forms>
</authentication>
<authorization>
<allow users="*" />
</authorization>
<location path="ABC.aspx">
<system.web>
<authorization>
<allow users="?"/>
</authorization>
</system.web>
I am not sure where I need to specify where to redirect in case of access denial. The default URL i specified not seems to be working

Accessing login page appends ReturnUrl on IIS?

I have a webforms application configured to use forms authentication. It works on my development machine but since I configured it on IIS, I get a ReturnUrl on my login page with the application name, Upon logging in I get back to the same login page logged in but without the returnUrl. Logging in again redirects me to the correct page finally
How can I stop this ReturnUrl appearing on my login page?
http://localhost/myApp/login.aspx?ReturnUrl=%2MyApp%2f
I have checked directory permissions & allowed all users on login page with authorization tag in my web.config but it does not work. Some of my web.config
<authentication mode="Forms">
<forms name="MyAuthCookie" timeout="30" loginUrl="login.aspx"></forms>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
.
.
.
<location path="login.aspx">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
Add defaultUrl tag and give the name of page where you want to redirect after login.
Suppose you want login and redirect to "xyz.aspx" page then you have to add below code in web.config file
Note: don't give loginUrl tag.
<authentication mode="Forms">
<forms name="MyAuthCookie" timeout="30" defaultUrl="xyz.aspx"></forms>
</authentication>
<authorization>

common authentication logic in asp.net membership

I m newb in asp.net. I m working for an example with Membership class in ASP.NET. I have some pages in my project e.g. default.aspx, page1.aspx, page2.aspx. I have put login control in default.aspx. Now I want to check authentication of user when user want to access any page. Already I achieved this thing to put below snippest in Page_Load event in every Page. But want some suggestion so that i can remove this duplicate code from every page. and implemete some logic which can be applicable on every page. Do i need to use global.asax or any class which could be inherite in all page an check authentication?
if(!HttpContext.Current.User.Identity.IsAuthenticated)
{
Response.redirect("default.aspx");
}
You can set up your default login page from the authentication element of the web.config file in the root of your asp.net application.
an example...
<authentication mode="Forms">
<forms loginUrl="Login.aspx"
protection="All"
timeout="30"
name=".ASPXAUTH"
path="/"
defaultUrl="default.aspx"
cookieless="UseDeviceProfile"
enableCrossAppRedirects="false" />
</authentication>
Controlling access to files and folders is done via the authorisation element.
an example...
<authorization>
<allow roles="Admin" />
<deny users="?" />
</authorization>
See the documentation for full details and more examples.
In .net, you can set this within the web.config using the authorization element.
<system.web>
<authorization>
<deny users="?" />
</authorization>
</system.web>
This will deny all users, who are not authenticated, access to any other page apart from the Login page which you specify in the authentication element.
<system.web>
<authentication mode="Forms">
<forms loginUrl="Login.aspx"
protection="All"
timeout="30"
name=".ASPXAUTH"
path="/"
requireSSL="false"
slidingExpiration="true"
defaultUrl="default.aspx"
cookieless="UseDeviceProfile"
enableCrossAppRedirects="false" />
</authentication>
</system.web>
As taken from here
For the purpose of the authorization, Baldy is correct.
For any other code that you may not want to duplicate per page, you may want to place it in a masterpage to which all of your pages belong.
Masterpages:
http://msdn.microsoft.com/en-us/library/wtxbf3hh.aspx

Login Membership .NET

Hi I was wondering what is the best way to force the user to login when arriving at a website, in .net. I have set up the Membership features and I was wondering what is the best way to ensure that no matter what address the user arrives at, they must first get authenticated before proceding to the page they requested. Any resources will be great, thanks.
Alter Web.config in application root to read:
<authentication mode="forms">
<forms loginUrl="Login.aspx" defaultUrl="/" />
</authentication>
<authorization>
<deny users="?" />
<allow users="*" />
</authorization>
Side note: Obviously, ASP.NET can only protect the requests that are handed down to ASP.NET engine. By default, it cannot enforce the security on static resources in IIS classic mode. In that case, to control access to static resources, they should be explicitly mapped to the ASP.NET ISAPI DLL in the IIS configuration.
More info about Authorization here: ASP.NET Authorization.
Forms Authentication explained
Here's a sample from a web.config
<forms loginUrl="Login.aspx"
protection="All"
timeout="30"
name=".ASPXAUTH"
path="/"
requireSSL="false"
slidingExpiration="true"
defaultUrl="default.aspx"
cookieless="UseDeviceProfile"
enableCrossAppRedirects="false" />

Resources