문제

I am Using ASP.NET web forms. In my application i need to be able to get to routedata of UserName in URL.

Url looks like this: localhost/profile/MyRAndomUserNAme

There are no problems to receive it in On_Load event like this:

string userName = Page.RouteData.Values["UserName"] as string;

But if i am in my Asmx WebService and try to receive UserName from URL, it just doesn't work. So how do i get around it?

PS: Its not a MVC project so i cant use var userName = ViewContext.RouteData.Values["UserName"]; on a view

도움이 되었습니까?

해결책

I have not done asp.net non-MVC for a while but I believe this is possible using the Current property of the HttpContext class. The Current property is static and should be always available during a web page post back.

Use HttpContext.Current.Request.QueryString["UserName"] to get the values you require.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top