Answered by:
Get Value From Custom URL

Question
-
User-698989805 posted
Hello friends! I run into a simple issue. I've a url where I can retrieve its value with the following if it's like this - AddUsers?user=USER-5678
string id = Request.QueryString["user"];
But when I customize it like this - AddUsers/user/USER-5678; Then unable to retrieve the value. Any better way to get the value? I know, there's and can't figure out at the moment and get null for the customized url.
Wednesday, November 28, 2018 11:36 AM
Answers
-
User475983607 posted
Hello friends! I run into a simple issue. I've a url where I can retrieve its value with the following if it's like this - AddUsers?user=USER-5678
string id = Request.QueryString["user"];
But when I customize it like this - AddUsers/user/USER-5678; Then unable to retrieve the value. Any better way to get the value? I know, there's and can't figure out at the moment and get null for the customized url.
Correct and the expected behavior! The second URL is commonly found in an application that supports routing. What kind of application are you building; MVC, Web API, Web Forms? Can you share code that reproduces the problem?
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, November 28, 2018 4:10 PM -
User475983607 posted
TechView
That's for WebForm @mgebhard. It says - object reference not set to an instance of an object.What says?
And are you using routing in Web Forms? Did you write custom code? Is there anyway you can share code that reproduces the issue?
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, November 28, 2018 4:18 PM -
User475983607 posted
Here it's - Custom url rewriting in the Global.asax:
routes.MapPageRoute("addUsersWithId", "AddUsers/{user}/{userCode}", "~/AddUsers.aspx");
Here is the link to redirect:
<ItemTemplate> <asp:HyperLink ID="HPlink" runat="server" Target="_self" Text="Edit" ForeColor="SteelBlue" NavigateUrl='<%# "AddUsers/user/" + Eval("userCode") %>'></asp:HyperLink> </ItemTemplate>
This is not custom URL rewriting it's routing. Also, you still have not provided the code to reproduce the issue... where is the code that fetches the route!
Does you code look like this?
Page.RouteData.Values["userCode"]
Or this?
<asp:Literal ID="Literal1" Text="<%$RouteValue:userCode%>" runat="server"></asp:Literal>
Perhaps try reading the openly published documentation.
https://msdn.microsoft.com/en-us/library/dd329551.aspx?f=255&MSPPError=-2147217396
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, November 28, 2018 4:48 PM
All replies
-
User475983607 posted
Hello friends! I run into a simple issue. I've a url where I can retrieve its value with the following if it's like this - AddUsers?user=USER-5678
string id = Request.QueryString["user"];
But when I customize it like this - AddUsers/user/USER-5678; Then unable to retrieve the value. Any better way to get the value? I know, there's and can't figure out at the moment and get null for the customized url.
Correct and the expected behavior! The second URL is commonly found in an application that supports routing. What kind of application are you building; MVC, Web API, Web Forms? Can you share code that reproduces the problem?
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, November 28, 2018 4:10 PM -
User-698989805 posted
That's for WebForm @mgebhard. It says - object reference not set to an instance of an object.
Wednesday, November 28, 2018 4:15 PM -
User475983607 posted
TechView
That's for WebForm @mgebhard. It says - object reference not set to an instance of an object.What says?
And are you using routing in Web Forms? Did you write custom code? Is there anyway you can share code that reproduces the issue?
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, November 28, 2018 4:18 PM -
User-698989805 posted
Here it's - Custom url rewriting in the Global.asax:
routes.MapPageRoute("addUsersWithId", "AddUsers/{user}/{userCode}", "~/AddUsers.aspx");
Here is the link to redirect:
<ItemTemplate> <asp:HyperLink ID="HPlink" runat="server" Target="_self" Text="Edit" ForeColor="SteelBlue" NavigateUrl='<%# "AddUsers/user/" + Eval("userCode") %>'></asp:HyperLink> </ItemTemplate>
Wednesday, November 28, 2018 4:24 PM -
User475983607 posted
Here it's - Custom url rewriting in the Global.asax:
routes.MapPageRoute("addUsersWithId", "AddUsers/{user}/{userCode}", "~/AddUsers.aspx");
Here is the link to redirect:
<ItemTemplate> <asp:HyperLink ID="HPlink" runat="server" Target="_self" Text="Edit" ForeColor="SteelBlue" NavigateUrl='<%# "AddUsers/user/" + Eval("userCode") %>'></asp:HyperLink> </ItemTemplate>
This is not custom URL rewriting it's routing. Also, you still have not provided the code to reproduce the issue... where is the code that fetches the route!
Does you code look like this?
Page.RouteData.Values["userCode"]
Or this?
<asp:Literal ID="Literal1" Text="<%$RouteValue:userCode%>" runat="server"></asp:Literal>
Perhaps try reading the openly published documentation.
https://msdn.microsoft.com/en-us/library/dd329551.aspx?f=255&MSPPError=-2147217396
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, November 28, 2018 4:48 PM -
User-698989805 posted
Thanks a lot @mgebhard. Found out from your solution - Finally this worked I mean that you provided:
Page.RouteData.Values["userCode"]
Wednesday, November 28, 2018 5:11 PM