Url在两个登录页面上重写

时间:2014-06-11 01:21:10

标签: asp.net vb.net rewrite urlrewriter.net

当我尝试重写我的登录页面网址时,我遇到了一些问题。 这是怎么回事。我有两个登录页面, FirstLoginPage.aspx SecondLoginPage.aspx , 我希望重写页面为 / FirstAuthen / SecondAuthen

每当用户想要进入第二个登录页面时,他们必须首先通过第一次登录。 我的web.config中有以下代码,默认文档设置为〜/ 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>

以及我的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

所有其他重写工作正常,并在项目启动时加载firstloginpage。除了firstloginpage.aspx之外,它不会像我希望的那样重写为〜/ FirstAuthen。我尝试了许多其他方式,但没有运气。我上面的代码有什么问题吗?请指教。感谢

1 个答案:

答案 0 :(得分:0)

在您的重写匹配规则中,您需要先在网址前设置/,所以它应如下所示:

 <match url="/FirstAuthen" />

在您的操作规则中,您可以将网页重定向到另一个网页,如下所示:

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

并为另一个做同样的事情