Asked by:
Hide the page name from the user in asp.net web form

Question
-
User858909527 posted
I have an asp.net web form project. The project has 5 pages. If the user fill page 1, he can go to page 2, and if he fill page 2 he can go to page 3 and so on. The problem is that the user can change the name of the page from the URL and he can skip page 1 and 2 and 3 and by this he can go to any page he want.
How can I hide the page name from the user? So, he can't go to another pages. I am new in programming, I need a help step by step as soon as possible.Monday, January 28, 2019 7:11 AM
All replies
-
User-943250815 posted
You can try Server.Transfer
https://docs.microsoft.com/en-us/dotnet/api/system.web.httpserverutility.transfer?view=netframework-4.7.2Monday, January 28, 2019 11:04 AM -
User858909527 posted
Dear jzero,
I want to hide the page name from the client to prevent him from going to the pages.
You can try Server.Transfer
https://docs.microsoft.com/en-us/dotnet/api/system.web.httpserverutility.transfer?view=netframework-4.7.2Monday, January 28, 2019 11:11 AM -
User-943250815 posted
You have to combine resources, like config on IIS a Default page or Use Routing and Server.Transfer.
This will just prevent user know page name. With Server.Transfer, browser URL remains unchanged after page load.
For Routing you can get more info here
https://docs.microsoft.com/en-us/previous-versions/cc668201(v=vs.140)On the other hand, looks like, Wizard Control could be applied on your case, with it you can make all 3 forms to be filled in a single page using steps.
There is a sample here https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.wizard?view=netframework-4.7.2Monday, January 28, 2019 12:11 PM -
User-893317190 posted
Hi zalnaser,
I think you need session to record the state of user, you could record which page the user has visited and the order of all your five pages.
When he(she) visit your page,check whether he has visited the page or not , if not , whether the current page he(she) is visiting is in write order , if not , redirect he(she) to right page.
Below is my sample code.
I have a model to record whether the user has visited the page and the url of the page.
public class MyModel { public string url { get; set; } public bool haveVisited { get; set; } }
if (!IsPostBack) { if (Session["data"] == null) { // prepare the data, which records the order to visit pages, here I have two pages, you could change to five pages. Session["data"] = new Dictionary<int, MyModel> { { 1,new MyModel { haveVisited=false,url="/ViewStateDemo/SessionTest.aspx"} }, { 2,new MyModel { haveVisited=false,url="/ViewStateDemo/second.aspx"} } }; } // get the data Dictionary<int, MyModel> data = Session["data"] as Dictionary<int, MyModel>; int currentPage = 1; MyModel obj=null; for (int i = 1; i <= 5; i++) // loop through 1-5 and get the first model that is not visited, which means this is the page he(she) should go { obj= data[i]; if(obj.haveVisited == false) { currentPage = i; break; } } int thisPage = 0; foreach (var item in data.Keys) // get the order of the page user wants to visit { if (data[item].url == Request.Path) { thisPage = item; } } if (currentPage != thisPage) // if the page user should go doesn't equal to the page user want to go { Response.Redirect(obj.url); // redirect the user to the right page } else { data[thisPage].haveVisited = true;// else mark the page as haveVisited } }
Best regards,
Ackerly Xu
Tuesday, January 29, 2019 4:32 AM -
User858909527 posted
jzero
You have to combine resources, like config on IIS a Default page or Use Routing and Server.Transfer.
This will just prevent user know page name. With Server.Transfer, browser URL remains unchanged after page load.
For Routing you can get more info here
https://docs.microsoft.com/en-us/previous-versions/cc668201(v=vs.140)On the other hand, looks like, Wizard Control could be applied on your case, with it you can make all 3 forms to be filled in a single page using steps.
There is a sample here https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.wizard?view=netframework-4.7.2yesterday I tried to use Server.Transfer(pagename,false); in my cs code
and then in the page I put <%@previouspageType virtualPath="~pagename.aspx" %>
But the page doesn't work with me
Wednesday, January 30, 2019 4:24 AM -
User-943250815 posted
I'm sure Server.Transfer works, but now, looks like you want a Cross-Page Post and get value of some control from Source page.
Here an article that may help
https://visualstudiomagazine.com/blogs/tool-tracker/2012/01/integrating-search-and-help-with-cross-page-posting.aspx
and
https://visualstudiomagazine.com/Blogs/Tool-Tracker/2012/03/Use-PreviousPageType-to-Simplify-Page-Data-Access.aspx
By the way, if using Server.Transfer there is no need to use Page DirectiveWednesday, January 30, 2019 7:51 PM