Hüseyin Demir
Hüseyin Demir

Reputation: 3

How to get RouteData.Value in class in ASP.NET webforms

I am getting route data value in Page_Load but I want to get this value in a class.

string id = Page.RouteData.Values["id"]; // works in Page_Load

I have tried this code in a class but it didn't work. It's returning null. I don't want to check in Page_Load() on every page. I just want to check using a function in a class if it's possible.

RouteData routeData = HttpContext.Current.Request.RequestContext.RouteData;

if(routeData != null)
{
    var id = routeData.Values["id"];
}
else
{
    // Routedata returning null;
}

Any idea?

Upvotes: 0

Views: 231

Answers (0)

Related Questions