How to login to a ASP.NET webpage automatically

Hi,
I need to figure out how to log a user in automatically when visiting an asp.net web page that requires forms authentication.

The case is:
I'm extending our corporate ASP.NET intranet site with a third party webapplication through an iframe. Our intranet uses windows authentication, but the page I'm accessing from the third party provider through the iframe, requires forms authentication. The credentials are however only the AD username as username and password.
How can I get the page to login automatically when a user visits the page witout redirecting to login.aspx?

I've tried some google searches but come up with nothing of use.

Regards
Jens
MYTAIRAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David H.H.LeeCommented:
Hi MYTAIR,
>>..How can I get the page to login automatically when a user visits the page witout redirecting to login.aspx?
You need to put one login page for Form authentication in web.config if the user not yet login through the system.
But, you may put some logic to bypass the login page that defined under other page that trying to invoke the page that need authentication.
eg:
                  //... server code that calling page that need authentication(eg: MemberTransactions.aspx), probably onClick event. You can apply it into your exact scenarios
                  FormsAuthentication.SetAuthCookie(YOURADUsername, false) ;
                  Response.Redirect("MemberTransactions.aspx", false);

Check this for further details:
http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.setauthcookie.aspx
0
MYTAIRAuthor Commented:
Hi x com,
I've tried your solution:

FormsAuthentication.SetAuthCookie(YOURADUsername, false) ;
Response.Redirect("MemberTransactions.aspx", false);

but it just redirects me to the login page. It appears the cookie is not being set in my session.
0
David H.H.LeeCommented:
Hi MYTAIR,
You can create the persist cookies there as described in the proposed MSDN site.
Response.Redirect("MemberTransactions.aspx", true);

Try delete the internet cache file and run the application again.
Lastly, post the code snippet here if the application still pointing to login page.

0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

MYTAIRAuthor Commented:
Hi x com,
I've tried it again. See code snippet below.

It causes a redirect to itself, which will never end. That is when it redirects to CWP_Default.aspx, it finds out the user is not logged in, and redirects back to CWPLogin.aspx.


CWPLogin.aspx
 
<script runat="server">
protected override void OnPreInit(EventArgs e)
    {
        base.OnPreInit(e);
             
        string username = "72315"; 
        
        FormsAuthentication.SetAuthCookie(username, true);
        
          
        Response.Redirect("http://dk-ta-cphrm2/CWP_WA/CWP_Default.aspx", true);
 
}

Open in new window

0
David H.H.LeeCommented:
Hi MYTAIR,
Sorry for the delay reply. May i see the code that resides inside CWP_Default.aspx? Could be some logic is causing the page redirection to Login page?
0
MYTAIRAuthor Commented:
Hi x com,
I wish I could, but I don't have access to the source code behind Login.aspx, because it's in a compiled dll.
0
David H.H.LeeCommented:
Hi MYTAIR,
Ok, you can download .net reflector to check the original source that resides via the compiled dll.
http://www.red-gate.com/products/reflector/
It may guarantee 100% conversion of the code, but give it a stab to check your source code.

Finally, it's worth noting that Microsoft recently announced that they would be releasing the .NET Framework code to the public under the Microsoft Research License (MS-RL). It's more flexible to check the working code that resides inside .net framework since VS2008.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.