MYTAIR
asked on
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
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
ASKER
Hi x com,
I've tried your solution:
FormsAuthentication.SetAut hCookie(YO URADUserna me, false) ;
Response.Redirect("MemberT ransaction s.aspx", false);
but it just redirects me to the login page. It appears the cookie is not being set in my session.
I've tried your solution:
FormsAuthentication.SetAut
Response.Redirect("MemberT
but it just redirects me to the login page. It appears the cookie is not being set in my session.
Hi MYTAIR,
You can create the persist cookies there as described in the proposed MSDN site.
Response.Redirect("MemberT ransaction s.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.
You can create the persist cookies there as described in the proposed MSDN site.
Response.Redirect("MemberT
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.
ASKER
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.
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);
}
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?
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?
ASKER
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.
I wish I could, but I don't have access to the source code behind Login.aspx, because it's in a compiled dll.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>>..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.SetAut
Response.Redirect("MemberT
Check this for further details:
http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.setauthcookie.aspx