Simple Html Menu in asp.net.. Broken url issue - c#

When I use simple menu built manually in html and css presents problem with the navigation. When I navigate a page that is inside a folder when i navigate away to somewhere outside of the current folder then the previous folder remains in the url and page not found message appears. I am currently in development stage. not deployed.

sounds like you need to use absolute URLs, not relative ones. so:
http://www.blah.com/category/page.html
or just
/category/page.html
NOT
page.html

It's because you don't return to your root when you try to redirect
e.g.
I have a page called Default.aspx that isn't in a folder and a page Page.aspx in the folder called SubFolder.
Your urls probably look like this to redirect:
Default.aspx
SubFolder/Page.aspx
When you try to redirect from Page.aspx to Default.aspx, you don't return to the root, so the code will look for a page called Default.aspx in the folder SubFolder, but it doesn't exist, that's why you're getting a page not found error.
You should write your urls like this:
~/Default.aspx
~/SubFolder/Page.aspx

Related

Visual Studio C# ASP.NET Cannot find resource but path returned is wrong

I apologize if this is a basic question, but allow me to just ask.
So I have three webpages.
/Project/MainPages/Default.aspx
/Project/Forum/Forum.aspx
/Project/Accounts/Login/Login.aspx
I am using html href to transfer between pages.
Issue is that, as long as I'm not in the login page, I can transfer between pages freely.
But once I move towards the login page and attempt to move to another page such as homepage or forum, it returns me Resource Not Found, with the path of:
/Project/Accounts/MainPages/Default.aspx or /Project/Accounts/Forum/Forum.aspx if I click on forum instead.
I've checked my hrefs are fine
<li>Home</li>
<li>Forum</li>
<li>Log In</li>
^ these are put in my masterpage. Naturally all pages will have these links if they are referenced to masterpage.
By the way, the links are generated when I "pick url" and specify the location of each web file.
Is it related to validation problems in login page?
Just to add, it contains red labels that checks if users entered correct detail formats before submitting the login button.
The login page contains both login and signup options. Signup redirects it to the signup page only, though.
The .. you are using means "Previous folder".
So if you're into /Project/MainPages and do .., it will resolve to the project root /Project, which is fine.
However, when you're in /Project/Accounts/Login and use .., you fall back to /Project/Accounts, not /Project. So your Main Pages and Forum folders are not visible (because you're one folder too far).
To solve this problem, instead of using relative paths, use absolute paths starting from the root of your project:
<li>Home</li>
<li>Forum</li>
<li>Log In</li>
or, only from your Login page, go back one more folder in the hierarchy to find the other two pages:
<li>Home</li>
<li>Forum</li>
<li>Log In</li>

Relative links with Razor in ASP.NET without MVC

We're working on a site that was set up with all the pages in the root directory. As a result all the links are referencing locations in the same directory they're located in by default...
Page
We've restructured it and some of the pages are now in sub folders, so the links throughout the site now need to be relative. I've read that a tilde (~) won't work in the markup when using Razor. ie Page
How can a link be formatted so that it points to something in the root directory?
Something like? Page
EDIT: Resolved with: Page
Try this:
#helper _href(string url)
{
#VirtualPathUtility.ToAbsolute(url)
}
To use it on a page:
linky
Edit: How I never knew about the built-in Href method is beyond me. You should definitely use that instead.
Use the Href method, like this:
#Href("SomePage")
Note that you don't need to use file extensions.
Glance at #Html.ActionLink
It allows you use controller name

Getting Current Page URL From Master Page with Routing

I'm trying to be able to determine which page url the user is loading from the master page.
So far I've been able to use
this.Request.RawUrl
to get the path of the page itself, which works fine for most cases.
However in this particular website, we use a lot of complicated routing, so something like (say)
/Product/5/2/Purchase
might redirect to /Purchase.aspx?ID=5Type=2
of which I'd want the actual aspx file path.
I've also tried this.Request.PhysicalPath, but that doesn't give the route and basically just appends the path the user requested to the virtual directory.
So how can I do it?
An asp.net Page treats a master page as just another control.
So if you want to get the page, you can always use the Page property provided by the MasterPage class.
I used this and worked :
Page.ToString().Replace("ASP.","").Replace("_",".")

Run a aspx page into a Sharepoint folder

I have a aspx page and I'd like to run it into a sharepoint folder. Is there a way to execute this page like a html page? What I really need is to run a c# code that is together the aspx page (code behind) to read a SQLite database and shows the result in a good interface (html-css-javascript).
Obs.: I have a assembly reference for the SQLite.
Thanks a lot!
You need to create an application page inside sharepoint and move your code in that application page. its very simple, please see this link.
http://www.c-sharpcorner.com/uploadfile/anavijai/how-to-create-custom-sharepoint-2010-application-page-using-visual-studio-2010/
Please note that application page only support web forms and not MVC
Not sure "run it into a sharepoint folder" means... You can't have page with code behind in regular SharePoint folders.
You can put ASPX pages (even with codebehind) in Layouts folder on server's disk and they will be avaiable with ....\layouts\your_page.aspx urls.

Hyperlink HTML page

I am using an asp page where I want to have a hyperlink that, if clicked, will load an html page in the browser.\but as i user the asp:hyperlink and I am also giving the path of the html page where the page is stored. However, when clicked, it is not loading that html page..
i am using the hyperlink as:
<asp:HyperLink ID="hlinkTest" runat="server">Preview</asp:HyperLink>
and i am giving the url as
hlinkTest.NavigateUrl = "file:///E:/user/aspnet_app/source/test.html";
what can be the better solution for getting html page in browser..
I would be concerned that by trying to access a specific file location, you're opening yourself up for problems. You might have some real trouble porting the site to a new location.
If the target file is in the same folder as your hyperling source you could use:
hlinkText.NavigateUrl = "~/test.html";
Good luck.
Try:
Preview
Don't forget that the client browser will be unable to load a file: url unless a file with that name and path exists and the user has read access to it. So in the OP's original example, unless the machine running the browser that's trying to load file:///E:/user/aspnet_app/source/test.html has a readable file at E:\user\aspnet_app\source\test.html, they're get a big fat error along the lines of file or directory does not exist or can't be found. Try giving the user an http: URL, absolute (http://www.mysite.org/foo/bar/baz.html) or relative (foo/bar/baz.html). If relative, the path will be taken relative to the URL of the current page.

Categories