Click here to Skip to main content
15,894,291 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have created a custom loging page for my mvc4 web application. But when an unauthorized user tried to access a controller, say Home/Index the pageis redirected to "/Account/Login?ReturnUrl=%2fhome%2findex". How can i redirect it to my User/Login.

Where is it set,I have removed my Account Controller,Account Views and Account Model,Still the page is redirecting to "/Account/Login?ReturnUrl=%2femployee%2findex".

please helpmeto fix this
Posted
Comments
Faisalabadians 24-Sep-13 9:05am    
where are you checking user's rights? I mean how you are determining if a particular user has access to home/index ?
id-athul 25-Sep-13 0:24am    
I use[Authorize]for all the controllers and for action links that doesn't need authorization i used [AllowAnonymous].

The problem occurs when a user explicitly typed the url without logging in
Faisalabadians 25-Sep-13 3:25am    
ok, until you find any solid solution, override AuthorizeCore redirect manually to unauthorize page. please let me know if you find any better solution craze.programmer@gmail.com
id-athul 25-Sep-13 4:21am    
Sorry i did not understand, can you explain it more
Faisalabadians 25-Sep-13 6:09am    
you have to write your own authorize attribute, in that attribute, override AuthorizeCore method and check for your conditions and if no condition matches then redirect to un authorize page.

1 solution

That setting sits in your web.config file.

XML
<authentication mode="Forms">
  <forms loginUrl="~/PageToLogin/Login" timeout="2880" slidingExpiration="true" name=".ASPXAUTH_MyAuthenticationCookie" />
</authentication>
 
Share this answer
 
Comments
id-athul 25-Sep-13 0:19am    
Hi Thanks Eduard Keilholz.I have added the following code
<forms loginUrl="~/User/Login" timeout="2880" slidingExpiration="true" name=".ASPXAUTH_MyAuthenticationCookie" />

Still its redirecting to http://localhost:2550/Account/Login?ReturnUrl=%2femployee%2findex

I dint mentionAccount/Login any where in theproject.I have removed all the files and folders related to "Accounts"
Eduard Keilholz 25-Sep-13 2:50am    
That is pretty strange...
id-athul 25-Sep-13 3:08am    
Yes,Thats what i am confused,There are 2 web.config files,one is inside the view folder and one outside,which one is main
Eduard Keilholz 25-Sep-13 4:34am    
You generally leave the on in the view folder alone, only when you'll need this only if you customize razor. The one in the root of your mvc project is your friend.
id-athul 25-Sep-13 7:53am    
Thanks :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900