By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,067 Members | 1,818 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,067 IT Pros & Developers. It's quick & easy.

Thread was being aborted

P: n/a
Hi,

When I do the Login using the code below I am getting the
System.Thread.ThreadAbortException(Thread was being abortefd) on the last
line of the below code i.e.
Response.RedirectFormsAuthentication.GetRedirectUr luID,isPersistent));

there is no original URL, therefore it is returning Default.aspx.

I don't know why I am getting the above exception.

private void ButtonLogin_Click(object sender, System.EventArgs e)

{

string sessionID = "";

string uID = txtUsername.Text;

string pwd = txtPassword.Text;
bool isPersistent = false; try

{

ESMLoginResultEnum loginResult = ESMSecurityModule.Login(uID, pwd, out
sessionID);

string userData = sessionID;

switch(loginResult)

{

case ESMLoginResultEnum.OK:

{

FormsAuthenticationTicket ticket = new
FormsAuthenticationTicket(1,uID,System.DateTime.No w,System.DateTime.Now.AddMinutes(AUTH_TIMEOUT),isP ersistent,userData,FormsAuthentication.FormsCookie Path);

// Encrypt the ticket.

string encTicket = FormsAuthentication.Encrypt(ticket);

HttpCookie cookie = new
HttpCookie(FormsAuthentication.FormsCookieName,enc Ticket);

cookie.Path = FormsAuthentication.FormsCookiePath;

// Create the cookie.

Response.Cookies.Add(cookie);

// Redirect back to original URL.

Response.Redirect(FormsAuthentication.GetRedirectU rl(uID,isPersistent));

break;

}

}

}

}

Regards,

Ekta


Nov 19 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Enhar:
Response.Redirect("someUrl") always throws a threadAbort exception.
Response.Reidrect("someUrl") calls Response.Redirect("someUrl", true)
with true meaning "end the response". So Response.End() is called which
throws that exception.

If you want, you can avoid the error by doing Response.ReidrecT("someUrl",
false)

or you could swollow the exception in a try/catch

try{
Response.Redirect("someUrl")
}catch (ThreadAbortException ex){}

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"enahar" <en****@hotmail.com> wrote in message
news:e0**************@TK2MSFTNGP15.phx.gbl...
Hi,

When I do the Login using the code below I am getting the
System.Thread.ThreadAbortException(Thread was being abortefd) on the last
line of the below code i.e.
Response.RedirectFormsAuthentication.GetRedirectUr luID,isPersistent));

there is no original URL, therefore it is returning Default.aspx.

I don't know why I am getting the above exception.

private void ButtonLogin_Click(object sender, System.EventArgs e)

{

string sessionID = "";

string uID = txtUsername.Text;

string pwd = txtPassword.Text;
bool isPersistent = false; try

{

ESMLoginResultEnum loginResult = ESMSecurityModule.Login(uID, pwd, out
sessionID);

string userData = sessionID;

switch(loginResult)

{

case ESMLoginResultEnum.OK:

{

FormsAuthenticationTicket ticket = new
FormsAuthenticationTicket(1,uID,System.DateTime.No w,System.DateTime.Now.AddM
inutes(AUTH_TIMEOUT),isPersistent,userData,FormsAu thentication.FormsCookiePa
th);
// Encrypt the ticket.

string encTicket = FormsAuthentication.Encrypt(ticket);

HttpCookie cookie = new
HttpCookie(FormsAuthentication.FormsCookieName,enc Ticket);

cookie.Path = FormsAuthentication.FormsCookiePath;

// Create the cookie.

Response.Cookies.Add(cookie);

// Redirect back to original URL.

Response.Redirect(FormsAuthentication.GetRedirectU rl(uID,isPersistent));

break;

}

}

}

}

Regards,

Ekta

Nov 19 '05 #2

P: n/a
Hi,

Session is still not timing out when there is no activity by the user for 15
minutes.

My web.config settings are as below.
also in the login page for the ticket I am adding 15 minutes.
What is wrong i am doing it..
Regards,
Ekta


FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(

1,

uID,

System.DateTime.Now,

System.DateTime.Now.AddMinutes(15),

isPersistent,

userData,

FormsAuthentication.FormsCookiePath);

:

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

<configSections>

<section name="AppConfiguration" type="PIT.ESH.Common.WebConfiguration,
PITSHCommon" />

</configSections>

<system.web>

<compilation defaultLanguage="c#" debug="true" />

<customErrors mode="RemoteOnly" />

<authentication mode="Forms">

<forms loginUrl="Security/Login.aspx" protection="All" timeout="2" path="/"
/>
</authentication>
<authorization>

<deny users="?" />

</authorization>

<trace enabled="true" requestLimit="10" pageOutput="false"
traceMode="SortByTime" localOnly="true" />

<sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data source=127.0.0.1;user id=sa;password="
cookieless="false" timeout="2" />

<globalization

requestEncoding="utf-8"

responseEncoding="utf-8"

culture="en-AU"

uiCulture = "en-AU"

/>

</system.web>

<AppConfiguration>

<!-- Application Settings -->

<add key="Web.EnablePageCache" value="true" />

<add key="Web.PageCacheExpiresInSeconds" value="3600" />

<add key="Web.EnableSsl" value="False" />

<add key="DB.ConnectionString" value="Data Source=DEVTEST-SQL1;User
ID=sa;Password=;Initial Catalog=Genesis2" />

<add key="Copyright.Message" value=" 2001-04 Positive IT Solutions Pty
Ltd." />

<add key="Copyright.EMail" value="" />

</AppConfiguration>

<appSettings>

<add key="Copyright.EMail" value="Et*****@Postitive-IT.com.au" />

</appSettings>

<system.runtime.remoting>

<application>

</application>

</system.runtime.remoting>

<location path="default.aspx">

<system.web>

<authorization>

<allow users="?" />

</authorization>

</system.web>

</location>

<location path="Security">

<system.web>

<authorization>

<allow users="?" />

</authorization>

</system.web>

</location>

<location path="Public">

<system.web>

<authorization>

<allow users="*" />

</authorization>

</system.web>

</location>

</configuration>
Nov 19 '05 #3

P: n/a
On Mon, 7 Mar 2005 17:09:01 +1100, "enahar" <en****@hotmail.com>
wrote:
Hi,

Session is still not timing out when there is no activity by the user for 15
minutes.

My web.config settings are as below.
also in the login page for the ticket I am adding 15 minutes.
What is wrong i am doing it..
Regards,
Ekta


Hi Etka:

Are you testing the Session timeout or the forms authentication ticket
timeout?

--
Scott
http://www.OdeToCode.com/blogs/scott/

Nov 19 '05 #4

P: n/a
I am writing the following code in the web.config file and the Login.aspx.cs
for the sessiopn TimeOut and for the forms authentication ticket timeout.

Also I am writing the following code in the Body tag of the Login.aspx page

<meta http-equiv="Refresh" URL="../Security/Login.aspx>

even then Session is still not timing out when there is no activity by the
user for 15 minutes.What is wrong I am doing it.Please suggest.

code in the session_end is as follows:
protected void Session_End(Object sender, EventArgs e)

{

FormsAuthentication.SignOut();

if (Session["SessionID"] != null)

{

try

{

ESMSecurityModule.killSession(Session["SessionID"].ToString());

}

catch

{

}

}

}
WEB.CONFIG

<authentication mode="Forms">

<forms loginUrl="../Security/Login.aspx" protection="All" timeout="15"
path="/" />
</authentication>

and for the forms authentication ticket TimeOut I am writing the following
code in the Login.aspx page:

LOGIN.ASPX PAGE

FormsAuthenticationTicket ticket = new
FormsAuthenticationTicket(1,uID,System.DateTime.No w,System.DateTime.Now.AddMinutes(15),false,userDat a,FormsAuthentication.FormsCookiePath);

// Encrypt the ticket.

string encTicket = FormsAuthentication.Encrypt(ticket);

HttpCookie cookie = new
HttpCookie(FormsAuthentication.FormsCookieName,enc Ticket);

cookie.Path = FormsAuthentication.FormsCookiePath;

// Create the cookie.

Response.Cookies.Add(cookie);

// Redirect back to original URL.

Response.Redirect(FormsAuthentication.GetRedirectU rl(uID,isPersistent),false);



Regards,

Ekta
"Scott Allen" <sc***@nospam.odetocode.com> wrote in message
news:l3********************************@4ax.com...
On Mon, 7 Mar 2005 17:09:01 +1100, "enahar" <en****@hotmail.com>
wrote:
Hi,

Session is still not timing out when there is no activity by the user for
15
minutes.

My web.config settings are as below.
also in the login page for the ticket I am adding 15 minutes.
What is wrong i am doing it..
Regards,
Ekta


Hi Etka:

Are you testing the Session timeout or the forms authentication ticket
timeout?

--
Scott
http://www.OdeToCode.com/blogs/scott/

Nov 19 '05 #5

P: n/a
Hi enahar:

Don't relay on the Session_End event. Have you tested by hitting the
site with the browser after over 15 minutes of inactivity?

--
Scott
http://www.OdeToCode.com/blogs/scott/
Nov 19 '05 #6

P: n/a


Yes I have tested by hitting the
site with the browser after over 15 minutes of inactivity?

Regards
Ekta

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.