Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Routing without MVC: authentication form
    text
    copied!<p>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! :)</p> <p><strong>UPD:</strong> I forgot - I <strong>don't use MVC</strong>. That's the problem. How to use rounig and form authentication without MVC</p> <p><strong>UPD2:</strong> more about my problem <br /> What I want to get: urls such “<code>mysite.com/content/123</code>”, “<code>mysite.com/login/</code>”, 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).<br /> That’s what I’m doing.<br /> In <code>global.asax</code> on <code>Application_Start</code>, register routes like this:<br /></p> <pre><code>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+" }} }); </code></pre> <p>Where <code>CustomRouteHandler</code> and <code>ContentRoute</code> – simple <code>IRouteHandler</code> classes, just like: ...</p> <pre><code>public IHttpHandler GetHttpHandler(RequestContext requestContext) { var page = BuildManager.CreateInstanceFromVirtualPath(VirtualPath, typeof(Page)) as IHttpHandler; return page; } </code></pre> <p>...</p> <p>All seems to be perfect: I’m getting <code>content.aspx</code> when go to <code>“/content/10”</code> and <code>login.aspx</code> when go to <code>“/login/”</code>. But…<br /> When I make content secured (in <code>web.config</code>, with <code>deny=”?”</code>), login form doesn’t work like expected.<br /> Now I can’t reach the <code>“/content/10”</code> page: <br /> <br /><strong>0.</strong> I’m typing <code>“/content/10”</code> in my browser. <br /><strong>1.</strong> Site redirects to <code>“/login/?ReturnUrl=%2fcontent%2f10”</code>. (Hm… seems like all problems starts here, right? :) <br /><strong>2.</strong> I’m trying to log in. No matter what credentials I’m entered… <br /><strong>3.</strong> …site redirects me to <code>“login?ReturnUrl=%2fContent%2f10”</code> (yellow screen of error - <code>Access is denied.</code> Description: <code>An error occurred while accessing the resources required to serve this request. The server may not be configured for access to the requested URL</code>.)<br /> So, the problem is how to get ASP.NET understand real <code>ReturnUrl</code> and provide redirection after login.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload