HengChin
HengChin

Reputation: 593

Url rewrite on two login page

I am having some problem when I try to rewrite my login page url. This is how. I got two Login page, FirstLoginPage.aspx and SecondLoginPage.aspx, I wish to rewrite to page to /FirstAuthen and /SecondAuthen.

Whenever the user wanted to go to the second login page, they must first pass the first login. I have the following code in my web.config with the default document set to ~/FirstAuthen

 <defaultDocument>
  <files>
    <add value="~/FirstAuthen"/>
  </files>
 </defaultDocument>

 <authentication mode="Forms">
   <forms defaultUrl="~/Home" loginUrl="~/SecondLoginPage.aspx" slidingExpiration="true" timeout="1440"/>
 </authentication>
 <authorization>
   <deny users="?"/>
 </authorization>

 <location path="FirstLoginPage.aspx">
   <system.web>
     <authorization>
       <allow users="?"/>
     </authorization>
   </system.web>
 </location>  

 <rewrite>
  <rules>
    <rule name="remove firstlogin" patternSyntax="Wildcard">
      <match url="FirstAuthen" />
      <action type="Rewrite" url="FirstLoginPage.aspx"/>
    </rule>
    <rule name="remove secondlogin" patternSyntax="Wildcard">
      <match url="SecondAuthen" />
      <action type="Rewrite" url="SecondLoginPage.aspx"/>
    </rule>
  </rules>
 </rewrite>

and the following code in my Global.asax

 Sub RegisterRoutes(ByVal routes As RouteCollection)
    'FirstLoginPage
    routes.MapPageRoute("First", "FirstAuthen/", "~/FirstLoginPage.aspx")

    'SecondLoginPage
    routes.MapPageRoute("Second", "SecondAuthen/", "~/SecondLoginPage.aspx")

    'other routes
 End Sub

All other rewrite work fine,and firstloginpage will be loaded when the project start. Except the firstloginpage.aspx, it doesn't rewrite to ~/FirstAuthen as I wish. I tried many others way, but no luck. Am I doing anything wrong with the above code? Please advise. Thanks

Upvotes: 0

Views: 148

Answers (1)

Ali
Ali

Reputation: 2592

in your rewrite match rule you need to set / before the url first, so it should look like this:

 <match url="/FirstAuthen" />

and in your action rule you can redirect your page to another one like below:

  <rule name="go to second auth" stopProcessing="true">
      <match url="/FirstAuthen"/>
      <action type="Redirect" url="SecondAuthen" redirectType="Permanent"/>
  </rule>

and do the same for the other one

Upvotes: 0

Related Questions