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
Related
This is my first time developing something in C# and in MVC. I deployed my application and everything seems to be functioning ok except for the navigation. The first thing you click on will direct you properly, but the second time will try to combine the pathing request with the first.
Ex. Clicking on Services drop down and click ProcessReports correctly returns the web page, with the URL:
http://{ServerName}/SupportPortal/Support/ProcessReports
Then, clicking on a dropdown and then DalimWebApp Dev returns a 404 error and the url is
http://{ServerName}/SupportPortal/Support/Support/DalimWebApp/Dev
Why are there two "Supports?"
Any ideas?
How are you generating the URL for your links?
If you're using an HTML anchor with an href value "Support/ProcessReports" instead of "/Support/ProcessReports" (mind the forward slash) the URLs will be relative to your current path. Try prepending the forward slash.
As #David mentioned, you could also use the built in helpers to generate the entire link for you if it's easier for you.
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
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.
I have a subdomain that is http://trade.businessbazaar.in . I am dynamically creating urls from database something in this manner http://trade.businessbazaar.in/mycompany. To display details, I have an index.aspx file there,thinking that on every request the index.aspx page will load and display data accodingly. Also, There is a masterpage on the index.aspx page from where i am capturing the text mycompany and query it in database to fetch result. But nothing seems to work.
A genuine link is http://trade.businessbazaar.in/Symparlife. But its unable to load index.aspx. I need a clean approach without any third party dll or rewriters. Directly to push some lines in config and start working. That is url will be the same but index page will get loaded...
In short, i want to say
I need the StackOverflow type clean url mechanism to fetch pages
Thanks in Advance
You can handle the Begin_Request event in Global.asax and add custom code to redirect to index.aspx and convert the parts of the URL into query string arguments. You should use Server.Transfer to keep the URL in the browser.
I'd recommend upgrading to 4.0 and using the Routing enine though. You should check if the standard routing is available as a download for ASP.NET 3.5. I am sure your code will get messy very soon. Been there, done that.
As #Mike Miller mentions in the comments the Routing engine ships with ASP.NET 3.5. You can check the documentation here - http://msdn.microsoft.com/en-us/library/system.web.routing(v=vs.90).aspx
Here is a tutorial on how to use it with Web Forms - http://weblogs.asp.net/scottgu/archive/2009/10/13/url-routing-with-asp-net-4-web-forms-vs-2010-and-net-4-0-series.aspx
For your case the code would be something like:
routes.MapPageRoute("company-index", "/{company}", "~/index.aspx")
And in index.aspx you can access the route value for company like this:
string company = (string)Page.RouteData.Values["company"];
Keep in mind that you'd better add something in the URL before your actual argument (the company name). If you don't you will have problems later on when because you may want to add a URL like "/Login" but then you will have to validate that users can't create a company named "Login". Not how Stack Overflow has "/questions/" before the actual question info in the URL.
.NET 3.5 app written in C# here with both jQuery and some ASP.NET AJAX UpdatePanel flavouring.
I'm running into an interesting issue. I created a pagination user control that is made up of LinkButtons. The user control fires off an event called CurrentPageChanged whenever someone clicks on a page, previous, first, or next buttons. The page using this pagination control is then responsible for getting the newest set of records based on the pagination control item clicked.
Now, the issue I'm running into is this:
If I have a url like this: http://localhost:2798/user/9794/profile, everything works fine. However, if I have a url with the trailing slash (i.e. http://localhost:2798/user/9794/profile/), my UpdatePanel falls on its face with a 405 error.
The exception in question is this:
[Exception] Sys.WebForms.PageRequestManagerServerErrorException: Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 405
Now, I looked at the requests through Chrome's Developer Tools, and I see that it's requesting this url:
http://localhost:2798/user/9794/profile/profile. It looks like if there's a trailing slash, it'll append an extra path.
Any ideas how I can get around this?
It looks like if there's a trailing slash, it'll append an extra path.
Yes, that's how relative URLs work. A browser uses the trailing slash to decide whether the URL refers to a folder (in which case a URL could refer to another file inside that folder), or a file (in which case it would have to look up to the parent folder). So <a href="profile"> inside the trailing-slash-URL will indeed be pointing at .../profile/profile.
Any ideas how I can get around this?
Use absolute URLs (or, better, root-relative URLs like href="/user/9794/profile" everywhere you make a link (either explicitly or via an ASP.NET control). Relative URLs are incompatible with the ‘routed’ style of URL where you may have a variable number of slash-separated bits of data in the URL.
And/or use only canonical URLs, so that the URL for any given resource is always fixed; if you go to the “wrong” version with an extra slash or other redundant stuff in the URL you get a 301 redirect to the “right” version.