I am developing a web application webform project. I have few web forms in it. I have some anchor elements that are performing redirection of pages. First let me show you the structure of my project:
I am trying to navigate to Customer/Home.aspx page from Login.aspx Page.
The issue I get is it automatically converts Home.aspx to Default.aspx. Here is how it resolves the Url:
And here is the html I am using:
<ul>
<li>Customer</li>
<li>Products</li>
<li>Sales Order</li>
<li>About</li>
</ul>
How should I resolve these urls correctly?
UPDATE
I already have tried to use the LinkButton control but the Issue remains the same:
<li>
<asp:LinkButton ID="lnk" PostBackUrl="~/Customer/Home.aspx" runat="server">Customer</asp:LinkButton>
</li>
based on my experience I'm providing you with the following solutions.
The solution can sometimes be simple. Just try the clear the browser catch files.
Right click on the start up web form (in your case guess it's 'Login.aspx') and click 'Set as start Page' before compiling.
Try to place '../' before the url like (../Customer/Home.aspx). But this cannot be the issue unless you're trying to redirect from inside a directory.
Please do reply me if this didn't solve your problem and check the URL on the HTML source code of your page, try to attach a screenshot if possible.
Related
In my ASP.NET Core MVC application, I have two subfolders in the views folder - one is Home and the other is Menu.
The Home folder contains Index.cshtml, and the Menu folder contains topMenu.cshtml. When I run the application the URL is
localhost/****/home/index
There is a sidebar where I put a link for topmenu.cshtml, when I click the Top Menu, it's opening the topMenu.cshtml view and the URL is
localhost:*****/Menu/topMenu
The problem is if I'm trying to click on the home page after opening the Top Menu the URL of the home page is changing to
localhost/****/menu/index
Even after I created separate controllers for both Home and Menu where the action result is returning the view. I also have a login page in my application so I set the default route as
{controller=Home}/{action=Login}/{id?}
You did not share the content of your topmenu.cshtml, but I guess you did not specify the asp-controller="Home" on your anchor tag. It should look something like this:
<a asp-controller="Home" asp-action="Index">Home</a>
You can read more about the anchor tag attributes here:
https://learn.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/built-in/anchor-tag-helper?view=aspnetcore-3.1#anchor-tag-helper-attributes
I use a System.Web.Security.MembershipProvider to do my login-stuff on my aspx-Page.
My default page is stored in Pages/Default.aspx.
I defined this page as default page in iis. When I call my page via server/Pages/Default.aspx and do the login, everything works fine.
But when I call only server and do the login here, I'm redirected to server/Default.aspx (without the Pages-directory) -> which leads to an error, page not found...
Is there a way to prevent this, without changing the folderstructure of my project?
EDIT:
My Login-Control on the master-page:
<asp:Login ID="LoginBox" runat="server" Width="339px" DestinationPageUrl="/Pages/Default.aspx" FailureText="Username or password wrong!">
I think you need to find the application context folder structure code on the aspx page,
please refer this :
How to get the physical location of an ASP.NET web application without using HttpContext.Current?
I am using Response.Redirect in ASP .NET C# application, to redirect to a different web page based on success or failure.
But Response.Redirect is not working. Instead or redirecting to the new link, the body or the contents of the target web page is appended to the existing URL. I tried it for a simple HelloWorld page and still its not working. For ex:
If I am in home page: http://www.example.com/test/default.aspx
and if I want to redirect to HelloWord html page, then the final URL would be
Response.Redirect("~/../hello.html"); but I get http://www.example.com/<p>Hello%20World!!</p>
Due to the improper URL, I am getting "Access Denied Error".
Thanks for the help in advance.
You should use:
Response.Redirect("~/hello.html");
if your hello.html is in the application root directory.
Or if you want a relative parent directory to the current page:
Response.Redirect("../hello.html");
~ references the application root directory, so with "~/.." you are trying to access a parent of the root directory, that is not allowed.
I think you should use Server.Transfer() instead. It will redirect you to a new page. For example:
Server.Transfer("Home.html")
if the page is in the same directory, otherwise just use relative link
You cannot redirect to a file that is outside of an IIS site, as "one level up from the app-root" probably is.
Add the following code to the Page_Load event:
Response.Redirect("http://www.microsoft.com");
I have successfully setup routing in Asp.Net 4.0 webforms. I have set up:
routeCollection.MapPageRoute("Default Page", "Default/{ProductName}/{CategoryName}", "~/Default.aspx");
However, problem is even though the user browses to default.aspx, the page still shows up. How can I avoid this? I want only the MapPageRoute to work. I want that when user browses to default.aspx some error should be thrown or 404 page should be shown etc. In short I do not the user to browse through default.aspx. How can I do this?
Thanks in advance :)
you can handle this issue through two ways.
In global.asax in Request_Start event check that if the requested url end by .aspx redirect to error page.
Use Url rewriter, by regular expression identify the wrong requests and redirect them to custom error page.
Never used routing in WebForms myself, but have you tried looking at the Request.Url? If that ends with/contains you could handle this by redirecting to an error page.
I am generating menus and sub menus on the fly in my Master Page.
I have a link which points (AddMenu, and give url to the logoff page) to a generic logoff page. It is a html page. Before logging off, I make sure that the Sessions are aborted and cleared.
When I deploy this application on Servers, the application fails to come up.
To correct, I add a new aspx page. say Logout.aspx
When I click on Logout link on the master page -- I add menu item -- to point ot Logout.aspx.
In the Page_Load event of Logout.aspx, I clear the sessions and then Response.Redirect to the logoff page (which I was doing in the Master Page initially).
This case the sessions are working perfectly fine. What could be the possible reason for it?
From what I understand it sounds like you initially were trying to clear the session in the master page code-behind. This code was supposedly tied to the logoff menu item but you said the item was a 'link which points to a generic logoff page'.
My guess is you were expecting the link to trigger a postback to the masterpage when it was actually just directing the user to the html page.
When you moved the code to the Page_Load of the new Logoff.aspx page, your session clearing code was triggered correctly when they requested the Logoff.aspx page.
If this is the case, what you have found is that there is a big difference between the following
Logoff
and
<asp:LinkButton ID="linkLogoff" runat="server" Text="Logoff" />