Link to home
Start Free TrialLog in
Avatar of mugsey
mugseyFlag 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
Avatar of guru_sami
guru_sami
Flag of United States of America image

-->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.
Avatar of 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
Avatar of guru_sami
guru_sami
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 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 =

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?
Avatar of Nasir Razzaq
Forgive my ignorance but is the function GetUserByUsername not expecting a valid/existing username?