TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Agalya T
NA
1
696
Error in Invalidcast exception type
Jun 16 2015 5:18 AM
While logging the web page the global.asax.cs triggers the Application_AuthenticateRequest method and triggers the event handler Application_AuthenticateRequest method in securitymodule.cs .
But in my code it was not triggering the Application_AuthenticateRequest method in securitymodule.cs.Due to this getting exception like system.invalidcastexception:"Unable to cast object of type 'System.Web.Security.FormsIdentity' to type 'AllianzLife.WebServices.Security.AllianzIdentity'" in the line
return
((
AllianzIdentity
)
HttpContext
.Current.User.Identity).Username; in securitycontent.cs file.
Kindly can anyone help me on the same.
Global.asax.cs
protected
void
Application_AuthenticateRequest(
object
sender,
EventArgs
e)
{
}
SecurityModule.cs
public
void
Init(
HttpApplication
application)
{
this.application = application;
application.AuthenticateRequest +=
new
EventHandler
(Application_AuthenticateRequest);
//Occurs when a security module has established the identity of the user
application.PreRequestHandlerExecute +=
new
EventHandler
(application_PreRequestHandlerExecute);
application.BeginRequest +=
new
EventHandler
(application_BeginRequest);
}
private
void
Application_AuthenticateRequest(
object
sender,
EventArgs
e)
{
if
(
HttpContext
.Current.User !=
null
&&
HttpContext
.Current.User.Identity.IsAuthenticated &&
HttpContext
.Current.User.Identity
is
FormsIdentity
)
{
FormsIdentity
formsIdentity = (
FormsIdentity
)
HttpContext
.Current.User.Identity;
principal =
new
AllianzPrincipal
(formsIdentity.Ticket);
HttpContext
.Current.User = principal;
SecurityUtil
.ResetAuthenticationTicket(principal);
}
}
}
Securitycontent.cs
public
string
Username
{
get
{
if
(!HasAuthenticated)
{
return
null
;
}
return
((
AllianzIdentity
)
HttpContext
.Current.User.Identity).Username;
}
}
Reply
Answers (
0
)
How do I post the following file to a webservice
Login In mvc4 using mongo db