I am trying to enable routing on an asp vb.net application.
I followed the next steps :
1) In global.asax,there is this code
<%@ Application Language="VB" %>
<%@ Import Namespace="System.Web.Optimization" %>
<%@ Import Namespace="System.Web.Routing" %>
<script runat="server">
Sub Application_Start(sender As Object, e As EventArgs)
RouteConfig.RegisterRoutes(RouteTable.Routes)
BundleConfig.RegisterBundles(BundleTable.Bundles)
End Sub
</script>
2) In the RouteConfig.vb i have this :
Imports System.Web
Imports System.Web.Routing
Imports Microsoft.AspNet.FriendlyUrls
Public Module RouteConfig
Public Sub RegisterRoutes(routes As RouteCollection)
Dim settings = New FriendlyUrlSettings()
settings.AutoRedirectMode = RedirectMode.Permanent
routes.EnableFriendlyUrls(settings)
routes.MapPageRoute("Services",
"Services/{SID}",
"~/Services.aspx")
End Sub
End Module
3) In the services.aspx page, i wrote this
Imports System.Web.Routing Partial Class Services Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
lblTest.Text = RouteData.Values("SID").ToString
End If
End Sub
End Class
When I run the page, I get the error message
"No object reference is specified in an object instance."
If I delete the line "lblTest.Text = RouteData.Values("SID").ToString" it is working, of course without the SID parameter
Sorry for bad english.