I am creating a website and I'm trying to implement routing feature. Most of the time it works fine, but I've found a problem while routing between different web forms placed at different levels from the root of the website.
The above picture shows all the routes defined and picture below shows the solution explorer of my project:
Home page(home.aspx) of my website is shown below:
On clicking the picture it opens a new page(singlepage.aspx) with whole article about the topic and contains the required url(sitename/heading/querystring):
But from there when i click on HOME button, it does not take me to home page, but instead gets me to the url like this:
Seems like it is not calling the "routeHome" route, instead calls "routeSinglePage".
This is how the html for taking us to HOME page is:
So I wanted to know how I can get it to the home page from singlepage.aspx by clicking on HOME button. Do I need to add new routes or something else.
Thanks
Change the HTML to:
<li>Home</li>
<li>About</li>
<li>Contact</li>
The "/" indicates an absolute path, you are currently using a relative path and hence the issue.
Related
I'm a newbie at asp.net and I have asp.net application with nested master pages. (.Net 3.5) I had a web form at root directory and I moved it a folder which I created under root. From this point I started to get "cannot use a leading .. to exit above the top directory" error while that web form loading. I digged on web and I tried prefixes "~", "/", "../" but I'm nowhere. my code as follows.
<li>
Add New Staff
</li>
I tried to create one more web form under "Staff" directory, but this form also generates same error while loading. Appreciate for help.
if i am not wrong you are using double code in href. it should be like this depending on your folder structure.
Add New Staff
And
For anyone who has found this thread, addressing relative paths has always created arguments over what is correct or not.
Depending on where you use the path to be addressed, it will depend on how you address the path.
Generally :
. and ./ do the same thing, however you wouldn't use . with a file name. Otherwise you will have the browser requesting .filename.ext as a file from the server. The proper method would be ./filename.ext.
../ addresses the path up one level from the current folder. If you were in the path /cheese/crackers/yummy.html, and your link code asked for ../butter/spread.html in the document yummy.html, then you would be addressing the path /cheese/butter/spread.html, as far as the server was concerned.
/ will always address the root of the site.
In ASP.NET Web Form, we normally use HyperLink server control to create URL as mason said.
<asp:HyperLink runat="server" NavigateUrl="~/Staff/New_Staff.aspx" Text="Add New Staff"/>
If you do not want use it, you can manually prepend with <%= ResolveUrl("~/") %>.
Add New Staff
Background:
We are redoing our website and trying to modernize it. We were initially experimenting with AngularJS but dropped it due to some of our users being on unsupported browsers. We ended up just doing VB webforms and updating the design and functionality of our site.
I was having an issue with buttons or items that cause a postback. When the page tries to postback it hits to the path but loses everything between the hostname and the last "/"
For example I have a login page set up in the location
/Secure/Account/Login.aspx
I have a route as well that directs from /Secure/Account/Login.
So when you visit the page you are at:
www.website.com/Secure/Accounts/Login
When I click the login button though, instead of posting back, I am directed to:
www.website.com/Login which doesn't exist so I get an error.
This occurs if I navigate to the page instead of using the route as well. So if I am at www.website.com/Secure/Accounts/Login.aspx and click the button, I end up on www.website.com/Login.aspx with an error.
This doesn't affect pages in the root directory as long as they do not use routing attributes. We have some pages that use routing attributes that have the same issue though.
We have page /Category.aspx in the root directory with the route
/Category/{Attribute1}/{Attribute2}/ configured for the page.
If I am on the page www.website.com/Category/Attribute1/Attribute2 when I click on a button that posts back, I end up at www.website.com/Attribute2 with an error.
The issue ended up being a really small piece of code from when we were working with Angular
On our master page .aspx we had included the line:
<base href="/">
Removing this line, which we didn't even need anymore fixed the issue.
I have a Website www.xyz.com hosted on IIS.
I have created few child applications within same website.
So, my url becomes www.xyz.com/app1, now on aap1 home page I have below link, which opens the page on same app1
Index
But when I click on the link, It removes application name (i.e., app1) from URL and browse like below
www.xyz.com/Masters/Index and I end up with resource not found error.
Whereas it should be www.xyz.com/app1/Masters/Index
I tried link with ../, /, ./ prefix for link but none of them seems to work. I'm a missing something?
Please help.
From within your app1 use an Html.ActionLink helper instead fo the hardcoded link:
#Html.ActionLink("Index", "Masters", "Index")
This should keep the existing routing of the current web application.
LinkExtensions.ActionLink Method (HtmlHelper, String, String, String)
You can also use #Url.Action instead if you prefer to just update the url within your mark-up:
Index
I created a new website in IIS called wbsite1. Then I added an application to website1 wich is a website called website2. The problem appeared when we tried to access links in website2. The browser always refers to the root url and redirect so we were trying to change all the urls in website2. For example, if we have a url in website2 like :
<a href='http://localhost:2030/website2/cms/default.aspx...'
and we click on that link the browser redirect us to :
http://localhost:2030/website1/default.aspx
Why am I getting this behavior? And what is the best workaround to integrate two websites without trying to mess with every link in the website? Thank you very much.
We are facing troubles when I try to access a page in the child application it redirects to the default page of the main application and gives the error:
Session state is not available in this context.
I found the solution for my question and it's this :
unfortunately i have to "rewrite" all our links in my code.
so i created a function which will automatically add prefix to external links,
and store base link for other site it configuration.
I did such project with success. thank u for all your replies
i found another solution also and it's using a web proxy but i can't use it in my scenario
I have a little problem with my Redirect in ASP.NET (C#)
I just got a domain which looks like this: http://www.example.com/subdirectory
So when I open my asp.net start page, the url looks like this: http://www.example.com/subdirectory/Startpage/Startpage.aspx
That's my Redirect in code behind:
Response.Redirect("~/UserSite/UserSite.aspx")
The problem now is, when I click on that button, I get redirected to
http://www.example.com/UserSite/UserSite.aspx
instead of
http://www.example.com/subdirectory/UserSite/UserSite.aspx
How can I get my web page to notice the subdirectory in the url?
Would be nice if someone could help me.
Thanks.
This may be because your website under the sub-drecitory hasn't been setup as it's own application within IIS7.
You can do this by:
Open IIS Manager
Open up the website and right click on the sub directory
Click on "Convert to Application"
You can then change the Application Pool if you wish to have a dedicated one or otherwise just click OK.
Response.Redirect("~/UserSite/UserSite.aspx") should then understand that /subdirectory/ is the default website directory