Answer 4
Hello
I have implemented this successfuly long back but for Form Based Users. See following code may it wil give you an idea
First you will have to check/update you
web config specially db connection information
*---------Start --- Web.Config
<?xml version="1.0"?>
<!--
Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config.comments usually located in
\Windows\Microsoft.Net\Framework\v2.x\Config
-->
<configuration>
<appSettings/>
<connectionStrings>
<add name="FBA_SQLConnectionString" connectionString="server=PRODCTSERV;database=PortalUsers;User id=sa;password=sa;" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<!-- Membership Provider-->
<membership defaultProvider="FBA_AspNetSqlMembershipProvider">
<providers>
<add name="FBA_AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="FBA_SQLConnectionString" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="1" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression="" />
</providers>
</membership>
<!-- Role Provider -->
<roleManager enabled="true" defaultProvider="FBA_AspNetSqlRoleProvider">
<providers>
<add name="FBA_AspNetSqlRoleProvider" connectionStringName="FBA_SQLConnectionString" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" applicationName="/" />
</providers>
</roleManager>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true"/>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="Forms"/>
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
</system.web>
</configuration>
*---------End --- Web.Config
Now create default.aspx page and see its CS file as mentioned below
*-------- Start -- Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Redirect("http://portal/_Layouts/Mylogin.aspx?uid=test&pwd=test");
}
}
*-------- End -- Default.aspx.cs
Now you need to create another page lets say MyLogin.aspx
*-------- Start -- MyLogin.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MyLogin.aspx.cs" Inherits="_MyLogin" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Login ID="Login1" runat="server" MembershipProvider="FBA_AspNetSqlMembershipProvider"
OnLoggingIn="Login1_LoggingIn" OnLoggedIn="Login1_LoggedIn">
</asp:Login>
</div>
</form>
</body>
</html>
*-------- End -- MyLogin.aspx
Here is Mylogin.aspx.cs code
*-------- Start -- MyLogin.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Security;
public partial class _MyLogin : System.Web.UI.Page
{
private bool bLoggedIn;
protected void Page_Load(object sender, EventArgs e)
{
string uid = Request.QueryString["uid"];
string pwd = Request.QueryString["pwd"];
bLoggedIn = true;
try
{
if (Membership.ValidateUser(uid, pwd))
{
FormsAuthentication.RedirectFromLoginPage(uid, false);
}
}
catch (Exception ex)
{
bLoggedIn = false;
}
if (bLoggedIn)
{
Response.Redirect("http://portal/");
}
}
protected void Login1_LoggingIn(object sender, LoginCancelEventArgs e)
{
}
protected void Login1_LoggedIn(object sender, EventArgs e)
{
Response.Redirect("http://portal/");
}
}
*-------- End-- MyLogin.aspx.cs
Now you will have to copy both Mylogin file under 12 hive/_Layout folder
Now run you project, and see the magic, the only concern is that both the database (asp.net) and Sql Server (FBA user should have same username and password.
Let me know it works for you or not.
Ashish