Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 110935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:18:19+00:00 2026-05-11T02:18:19+00:00

Now I’m trying to work with System.Web.Routing. All is just fine, but I can’t

  • 0

Now I’m trying to work with System.Web.Routing. All is just fine, but I can’t understand how to make form authentication work with url routing (return url, redirection, etc). Google says nothing. Help! 🙂

UPD: I forgot – I don’t use MVC. That’s the problem. How to use rounig and form authentication without MVC

UPD2: more about my problem
What I want to get: urls such “mysite.com/content/123”, “mysite.com/login/”, etc using Routes. It’s important to make login page works like “regular” ASP.NET login form (redirects to login from secure area when not login on, and redirect back to secure area when loggined).
That’s what I’m doing.
In global.asax on Application_Start, register routes like this:

routes.Add('LoginPageRoute', new Route('login/', new CustomRouteHandler('~/login.aspx'))); routes.Add('ContentRoute', new Route('content/{id}', new ContentRoute('~/content.aspx')) {     Constraints = new RouteValueDictionary {{ 'id', @'\d+' }} }); 

Where CustomRouteHandler and ContentRoute – simple IRouteHandler classes, just like: …

public IHttpHandler GetHttpHandler(RequestContext requestContext) {     var page = BuildManager.CreateInstanceFromVirtualPath(VirtualPath, typeof(Page)) as IHttpHandler;     return page; } 

…

All seems to be perfect: I’m getting content.aspx when go to “/content/10” and login.aspx when go to “/login/”. But…
When I make content secured (in web.config, with deny=”?”), login form doesn’t work like expected.
Now I can’t reach the “/content/10” page:

0. I’m typing “/content/10” in my browser.
1. Site redirects to “/login/?ReturnUrl=%2fcontent%2f10”. (Hm… seems like all problems starts here, right? 🙂
2. I’m trying to log in. No matter what credentials I’m entered…
3. …site redirects me to “login?ReturnUrl=%2fContent%2f10” (yellow screen of error – Access is denied. Description: An error occurred while accessing the resources required to serve this request. The server may not be configured for access to the requested URL.)
So, the problem is how to get ASP.NET understand real ReturnUrl and provide redirection after login.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T02:18:20+00:00Added an answer on May 11, 2026 at 2:18 am

    These steps should allow you to implement the required behaviour.
    To summarize:

    1. You are using routing but not MVC. My example will map a url like http://host/Mysite/userid/12345 onto a real page at http://host/Mysite/Pages/users.aspx?userid=12345.
    2. You want to control access to these addresses, requiring the user to logon. My example has a page http://host/Mysite/login.aspx with a standard login control, and the site is configured to use forms authentication.

    Step 1

    I’ve ‘hidden’ the contents of the Pages folder using this web.config in the Pages folder:

      <?xml version='1.0'?>   <configuration>     <system.web>       <httpHandlers>         <add path='*' verb='*'             type='System.Web.HttpNotFoundHandler'/>       </httpHandlers>       <pages validateRequest='false'>       </pages>     </system.web>     <system.webServer>       <validation validateIntegratedModeConfiguration='false'/>       <handlers>         <remove name='BlockViewHandler'/>         <add name='BlockViewHandler' path='*' verb='*' preCondition='integratedMode' type='System.Web.HttpNotFoundHandler'/>       </handlers>     </system.webServer>   </configuration>   

    This ensures that if anyone uses a url like http://host/Mysite/Pages/users.aspx?userid=12345, then they receive a standard 404 response.

    Step 2

    My top level web.config file contains (as well as all the standard stuff) this location element:

      <location path='userid'>     <system.web>       <authorization>         <deny users='?'/>       </authorization>     </system.web>   </location> 

    This prevents anonymous access to urls of the form http://host/Mysite/userid/12345 which means users will be automatically redirected to login.aspx, then if they provide valid credentials, they will be redirected to the correct location.

    Step 3

    For reference here is my global.asax:

    <script RunAt='server'>      void Application_Start(object sender, EventArgs e)     {         // Code that runs on application startup         RegisterRoutes(RouteTable.Routes);      }      public static void RegisterRoutes(RouteCollection routes)     {         routes.RouteExistingFiles = true;         routes.Add('UseridRoute', new Route         (            'userid/{userid}',            new CustomRouteHandler('~/Pages/users.aspx')         ));     }  </script> 

    And here is my route handler:

    using System.Web.Compilation; using System.Web.UI; using System.Web; using System.Web.Routing; using System.Security; using System.Web.Security;   public interface IRoutablePage {     RequestContext RequestContext { set; } }  public class CustomRouteHandler : IRouteHandler {     public CustomRouteHandler(string virtualPath)     {         this.VirtualPath = virtualPath;     }      public string VirtualPath { get; private set; }      public IHttpHandler GetHttpHandler(RequestContext           requestContext)     {         var page = BuildManager.CreateInstanceFromVirtualPath              (VirtualPath, typeof(Page)) as IHttpHandler;          if (page != null)         {             var routablePage = page as IRoutablePage;              if (routablePage != null) routablePage.RequestContext = requestContext;         }          return page;     } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 69k
  • Answers 69k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Innovation in an existing organisation will nearly always challenge the… May 11, 2026 at 12:41 pm
  • added an answer Your best friend as a Linux web developer is IEs4Linux,… May 11, 2026 at 12:41 pm
  • added an answer Just round the timestamp to a few seconds - maybe… May 11, 2026 at 12:41 pm

Related Questions

now i need to insert some data from the sqlserver into a word,i know
Now I'm sure we're all well aware of the relative merits of Linux vs
Now I have a stack of free time on my hands, I wanna get
Now I know about the normal CSS list styles (roman, latin, etc) and certainly
Now I know that bigint is 2^64; that is, more atoms than there are

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.