Forms Authentication, .Net 3.5 + IIS 6 - asp.net

I changed the Intranet site's authentication method from Windows to Forms, using AD authentication. It works when I launch it from VS 2008, goes directly yo login.aspx page and after loggin in goes to default.aspx.
When I use the URL it tries to go to default.aspx directly and says you are not authorized to view this page, instead of going to login.aspx page. Not sure what I am missing here. In IIS, I enabled anonymous access and checked everything else off. In web.config I have the following:
<authentication mode="Forms">
<forms name=".ADAuthCookie" loginUrl="Account/Login.aspx" defaultUrl="Default.aspx" timeout="5" />
</authentication>
<authorization>
<deny users="?"/>
<allow users="*"/>
</authorization>
<membership defaultProvider="CMSOracleMembershipProvider">
<providers>
<add name="CMSOracleMembershipProvider"
type="Oracle.Web.Security.OracleMembershipProvider, Oracle.Web, Version=2.112.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342"
connectionStringName="CMSConnectionString"
applicationName="/"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="false"
passwordFormat="Hashed"
maxInvalidPasswordAttempts="4"
minRequiredPasswordLength="9"
passwordAttemptWindow="8"/>
</providers>
</membership>
<roleManager enabled="true" defaultProvider="CMSOracleRoleProvider">
<providers>
<add name="CMSOracleRoleProvider"
type="Oracle.Web.Security.OracleRoleProvider, Oracle.Web, Version=2.112.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342"
connectionStringName="CMSConnectionString"
applicationName="/"/>
</providers>
</roleManager>
I don't have an asp login control, but a couple of textboxes for id and password and I handle the authentication using AD.
I appreciaet your help.

First off, read this: http://support.microsoft.com/kb/326340
Second, it sounds like maybe the directory holding your login.aspx page may not be configured to allow anonymous access. You will need to drop a web.config file in that directory that is set to allow everyone.

Related

Forms Authentication set to None, but authentication with SQL Server is still being attempted

How can I disable forms authentication? Every time I navigate to a page, the page tries to authenticate through an SQL instance on server. I have set forms authentication to none, but still no change.
http://go.microsoft.com/fwlink/?LinkId=169433 -->
<system.web>
<httpRuntime maxRequestLength="65536" executionTimeout="3600"/>
<compilation debug="true" targetFramework="4.0" />
<!--<authorization>
<allow users="*"/>
</authorization>-->
<!--<authentication mode="None">
<forms loginUrl="~/Account/Login" timeout="2880" defaultUrl="~/" />
</authentication>-->
<profile defaultProvider="DefaultProfileProvider">
<providers>
<add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider,
System.Web.Providers, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"
connectionStringName="DefaultConnection" applicationName="/" />
Okay, so I went with leaving Forms Authentication enabled, and rather setup IIS to have access rights to an instance of SQL Express installed the server. All pages work fine now.

ASP how to get authorization rules in code? Not section from web.config, but actual rules

Well, to be honest, problem is why 'currentUser.Identity.Name' is blank.
Options are:
`<authentication mode="Windows">
</authentication>
<identity impersonate ="false"/>`
And IIS 7 Integrated Windows Authentication is enabled, 'Anonymous access’ disabled.
(It was mantioned here)
App is executing on local computer, in the same domain.
When I'm trying to write:
<authorization>
<allow users="MY_USER_NAME"/>
<deny users="?"/>
</authorization>
I get page 401.2, access forbidden.
And now, i think, options are inhereted from somwhere, and 'Anonymous access’ is still enabled. So, how i need to check the actual value in code.
UPDATE
Role manager is this:
<roleManager defaultProvider="DefaultRoleProvider" enabled="true">
<providers>
<add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/"/>
</providers>
</roleManager>

Untrusted domain error when using membership

I'm trying to develop an ASP.NET website which has registration and login functions. To do this, I'm using Membership by following this guide:
http://msdn.microsoft.com/en-us/library/ff648345.aspx
I've run Aspnet_regsql.exe and set up the database, and also changed by Web.config file to reflect this:
<connectionStrings>
<add name="MsSqlConnection" connectionString="Data Source=fostvm;Initial Catalog=db_74;User ID=user74;password=mypassword;Integrated Security=SSPI;" />
</connectionStrings>
<authentication mode="Forms">
<forms loginUrl="Account/Login.aspx"
protection="All"
timeout="30"
name="AppNameCookie"
path="/FormsAuth"
requireSSL="false"
slidingExpiration="true"
defaultUrl="default.aspx"
cookieless="UseCookies"
enableCrossAppRedirects="false" />
</authentication>
<authorization>
<deny users="?" />
<allow users="*" />
</authorization>
<membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="15">
<providers>
<clear />
<add
name="SqlProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="MsSqlConnection"
applicationName="WebSite10"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="true"
requiresUniqueEmail="true"
passwordFormat="Hashed" />
</providers>
</membership>
I don't get any errors while loading the log in or registration page, but when I try to log in with dummy account data I get this error thrown:
Login failed. The login is from an untrusted domain and cannot be used with Windows authentication.
I've Googled it and found loads of threads from different forums and blogs but no solutions have worked.
Is there any glaring error in my config that I've missed?
Thanks.
My guess would be, that in your connection string you have.
Data Source=fostvm;Initial Catalog=db_74;User ID=user74;password=mypassword;Integrated Security=SSPI;
And can someone correct me, that when you have Integrated Security=SSPI specified, the User ID and password are ignored and windows authentication will be used? In this case most likly it would be Application Pool account, or maybe even IUSR_Account, for anonymous access, which may not have permissions to your database.
So to sum it up - try to remove the Integrated Security=SSPI from connection string, or replace it with Integrated Security=false

how to secure webform by anonymous users using login form in asp.net web application

I have a asp.net web application with three webforms say SecuredWebForm.aspx,UnSecuredWebForm.aspx and LoginForm.aspx.
i want SecuredWebForm.aspx to be accessed only when user log in using LoginForm.aspx.
and for UnSecuredWebForm.aspx,there is no need to log in.
How do i achieve it?
Thanks in advance.
Here's a guide for it: http://www.codeproject.com/Articles/13872/Form-authentication-and-authorization-in-ASP-NET
Another guide how to do it:
http://support.microsoft.com/kb/301240/EN-US
http://support.microsoft.com/kb/316871
You can use this - based on location attribute
<configuration>
<location path="SecuredWebForm.aspx">
<system.web>
<authorization>
<allow users="..."/>
</authorization>
</system.web>
</location>
</configuration>
Nota : you adjust value of users
Link : http://msdn.microsoft.com/en-us/library/b6x6shw7%28v=vs.71%29.aspx
If you have security architecture , you can use IsAuthenticated property
Link : http://msdn.microsoft.com/en-us/library/system.web.httprequest.isauthenticated.aspx
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
}
It would be good to use Membership class for this purpose. If you don`t have specific requirement.
If you have created the NewProject with WebApplication, then VisualStudio might have setup the all concern configuration for you in web.config something like following:
Edit web.config by adding <authorization...>...</authorization> elements. It will prevent anonymous user by accessing authorize contents.
<configuration>
<connectionStrings>
<add name="ApplicationServices" connectionString="ConnectionStringData" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx" timeout="2880" />
</authentication>
<authorization>
<deny users="?"/>
</authorization>
<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"
enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
applicationName="/" />
</providers>
</membership>
...
...
</system.web>
...
...
</configuration>
You may also need to secure the webform from anonymous users, then you may write following:
protected void Page_Load(object sender, EventArgs e)
{
if (!User.Identity.IsAuthenticated)
Response.Redirect("Login.aspx");
// Todo add code here.
}

How to create default users in Web.config for Membership

how can I add default users in my web.config to test my asp: login control
Thanx
I was wrong wrong wrong in my initial answer. You can set default users in Web.config if you do some simple authentication by yourself, but it doesn't seem to work when you are using the Login control.
I did some research, and it seems that, if you use the Login control, you can't set default users in Web.config and you have no way but setting a provider (as in a database) to store users credentials.
You can follow this tutorial from MSDN to configure what database to use:
Configuring an ASP.NET Application to Use Membership
The Web.config stuff:
<configuration>
<connectionStrings>
<add name="MySqlConnection" connectionString="Data
Source=MySqlServer;Initial Catalog=aspnetdb;Integrated
Security=SSPI;" />
</connectionStrings>
<system.web>
<authentication mode="Forms" >
<forms loginUrl="login.aspx"
name=".ASPXFORMSAUTH" />
</authentication>
<authorization>
<deny users="?" />
</authorization>
<membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="15">
<providers>
<clear />
<add
name="SqlProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="MySqlConnection"
applicationName="MyApplication"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="true"
requiresUniqueEmail="true"
passwordFormat="Hashed" />
</providers>
</membership>
</system.web>
</configuration>

Resources