如何使用路由规则限制对文件夹的访问?

时间:2014-01-30 14:49:57

标签: asp.net asp.net-routing

我想通过将此规则添加到根Web.config

来重新限制对名为Authenticated的文件夹的访问
<location path="Authenticated">
    <system.web>
      <authorization>
        <deny users="?" />
      </authorization>
    </system.web>
  </location>

仅当我不使用路由规则时,规则才能正常工作。我需要您的帮助才能了解如何启用路由规则。

例如,规则适用于此网址:../ locahost / Authenticated / CarList.aspx并且不适用于路由:../ localhost / en-us / car-list.aspx

我还添加了一个Web.config Authenticated文件夹根目录,我得到了相同的结果。

感谢您的帮助!


修改

这是设置路线的代码

 Public Shared Function GetUrlByRoute(session As HttpSessionState, pageName As String, routeName As String, Optional dictionary As Dictionary(Of String, Object) = Nothing, Optional setLanguage As String = "") As String
        Dim parameters As RouteValueDictionary
        Dim vpd As VirtualPathData
        Dim nextLanguage As String = "fr-ca"
        Dim currentLanguage As String = "fr-ca"

        If dictionary Is Nothing Then
            dictionary = New Dictionary(Of String, Object)
        Else
            If dictionary.ContainsKey("pageName") = True Then
                'Remove the old page name to set the new requested page name for hyperlink
                dictionary.Remove("pageName")
            End If
            If dictionary.ContainsKey("language") = True Then
                'Just in case
                dictionary.Remove("language")
            End If
        End If

        dictionary.Add("pageName", pageName)

        UrlHelper.GetUrlLangage(session, False, nextLanguage, currentLanguage)
        'Set the switch language link to next language lnkEnglish
        If setLanguage IsNot String.Empty Then
            dictionary.Add("language", setLanguage)
        Else
            dictionary.Add("language", currentLanguage)
        End If

        parameters = New RouteValueDictionary(dictionary)
        vpd = RouteTable.Routes.GetVirtualPath(HttpContext.Current.Request.RequestContext, routeName, parameters)
        Return vpd.VirtualPath

    End Function

全球性的asax

Sub RegisterRoutes(ByVal routes As RouteCollection)

        routes.Add("Page", New Route("{language}/{pageName}", New UrlRoutingHandlers()))
        routes.Add("Account", New Route("{language}/{pageName}/{id}", New UrlRoutingHandlers1()))

    End Sub

UrlHandler

Public Function GetHttpHandler(ByVal context As System.Web.Routing.RequestContext) As System.Web.IHttpHandler Implements System.Web.Routing.IRouteHandler.GetHttpHandler
    Dim language As String = context.RouteData.Values("language").ToString().ToLower()
    Dim pageName As String = context.RouteData.Values("pageName").ToString()

    Dim oUtilisateurConferance As Data.DataView = vwRouteMappingURL.Where("FriendlyPageName = '" + pageName + "'")

    For Each oRow As DataRowView In oUtilisateurConferance
        Return TryCast(BuildManager.CreateInstanceFromVirtualPath(oRow("VirtualPath").ToString(), GetType(Page)), Page)
    Next

    Return Nothing

End Function

0 个答案:

没有答案