Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
When I run optimization report for my webmatrix website, I get multiple issues stating:
"the page contains unnecessary redirects". This is the code snippet that causes the problem:
HTML
if(!WebSecurity.IsAuthenticated)
   {
      //navigate to login page
       Response.Redirect(App.PathUserLogin + "?returnUrl=" + Request.Url.LocalPath);
   }

Before using some pages the user has to log in and the above code is trying to redirect him/her to the login page (if he is not logged in). So why is it detected as unnecessary and how can I fix this?
Posted

1 solution

Maybe could help the approach used in this tutorial[^]:
- create a subfolder (e.g. Members);
- put files you want to protect into this subfolder;
- in the Members subfolder, create a file named _PageStart.cshtml. When any page in the subfolder is requested, this page runs first;
- in the _PageStart.cshtml file, call WebSecurity.IsAuthenticated to determine whether the user is logged in. If they are not, redirect them to the login page.
 
Share this answer
 
Comments
cs101000 8-May-13 4:22am    
Well I had implemented this and it was working. Problem was the given SEO error which I realized it's not important in my case according to this:
http://blogs.msdn.com/b/carlosag/archive/2009/06/12/redirects-301-302-and-iis-seo-toolkit.aspx
(Enter IIS SEO Toolkit, number 3)

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