Avatar of mugsey
mugsey
Flag for United Kingdom of Great Britain and Northern Ireland asked on

FormsAuthentication.RedirectFromLoginPage not working

ASP.NET app working fine locally using memberhip provider and in code I authenticate at login

FormsAuthentication.RedirectFromLoginPage............

Works great.  But if I put on test server I get authenticaion error "unkown user"  .  It is using the same database so the user is there.

However I ripped out the code and used a login control and it works fine on both local and test servers.

My question is why?  I want to use

FormsAuthentication.RedirectFromLoginPage   in code
ASP.NETC#Visual Basic.NET

Avatar of undefined
Last Comment
Nasir Razzaq

8/22/2022 - Mon
guru_sami

-->I get authenticaion error "unkown user"
Is that your custom error message or system generated?
Can you post the code you use for authentication and web.config.
mugsey

ASKER
HI guru sami

It is standard web.config stuff for membership.

It actually fails on this login code

 var user = UserService.GetUserByUsername(username.Text);

It works fine on my local pc and dev server BUT it does not work on the dev server if it returns null.

So if I put in wrong username it works fine locally but for some reason it errors saying unkown user on dev server
ASKER CERTIFIED SOLUTION
guru_sami

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
mugsey

ASKER
HI Yes

It is using custom membership provider that inherits from standard membership.

Username exists in database but I was testing for null user, ie, putting in wrong username

So if I put in wrong username on local PC it works fine handling null value returned but on dev server looking at the SAME database I get the same exepected behaviour unkown user but it throws an authentication exception "unkown user"

So I think my question is why is  that if I can return NULL to

var user = UserService.GetUserByUsername(username.Text);

which works fine on my local PC

but if I return NULL to

var user = UserService.GetUserByUsername(username.Text);

I get unhandled exception "Uknown user"  - on the dev server it cannot seem to handle having a null passed to         var user =

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
guru_sami

hmmm nothing else poping up ... can you try returning an empty string or empty object from GetUserByUsername instead of null if user is not found and see what the code does?
Nasir Razzaq

Forgive my ignorance but is the function GetUserByUsername not expecting a valid/existing username?