I have uploaded the nerddinner sample to "www.example.com/test/nerd". When a mouse is on menu tab such as "Find a host" then the link is shown at the bottom of Internet explorer as "www.example.com/test/nerd/Dinner" with the contoller name "Dinner". When the mouse is on the main logo which is on top and left, the link shown as "www.example.com". So it direct me to "www.example.com" instead of "www.example.com/test/nerd"
Where can I change it? I have tried to change the "start url" from the application property, but it did not work.
The NerdDinner application links to the / path when you click on the logo. This points you to the domain root: example.com.
If you want the link to point to your home page instead, there are two ways of doing that:
Have the link point to ~ instead - that's the application root. If you configure the directory you installed NerdDinner in as an IIS application, the controller action with the "" route will handle the request.
Change the <a href="/" to point to your controller action by name: <a href="<%= Url.Action("Index","Home") %>"
Both ways work, but I recommend using the first one, because it will point to whatever action is routed to ""; in other words, if you change the name of your home page action, for example, the link will still work.
This application assumes that is installed in the root of the domain, and therefore just contains the path "/". You'll need to edit NerdDinner/Views/Shared/Site.Master. The line you need to touch is
<h1></h1>
Try changing this to
<h1></h1>
I don't have ASP.NET set up anywhere I can try this, so it probably won't work as is. Hopefully that will at least get you started if it doesn't work perfectly.
Related
I have on my development machine (Windows 10 Pro) and the IIS Web Server installed.
I used VS 2017 to develop a .NET web application. It works fine when it is run in VS. The menu links find their correct action methods. It performs as expected.
I have a problem in IIS whereby I have published the .NET (.NET framework 4.8) web application.
The publish to IIS created the folder on my C drive: inetpub\wwwroot\ProfileAndOrBlog.
I launch the web app in the browser with this URL: http://localhost/ProfileAndOrBlog.
I then sign into the web app using a top menu item just fine. That menu link is coded in the view as:
<li>#Html.ActionLink("Sign In", "SignIn", "SignIn", routeValues: null, htmlAttributes: new { id = "signinBtn", #class = "btn btn-primary my-signin-btn" })</li>
The URL generated is: http://localhost/ProfileAndOrBlog/SignIn/SignIn
After sign in, I get this page.
The URL generated is: http://localhost/ProfileAndOrBlog/User
I can now click on any side bar menu (a function of the app) - a link.
When I use the side bar menu link 'Make Suggestions' coded in the view as:
<i class="fa fa-edit fa-fw"></i> Make Suggestions
I get a 'This localhost page can't be found'.
The URL generated is: http://localhost/UserSuggestionMaint/Index.
It does not have the ProfileAndOrBlog/ as part of the route.
Note: if I manually add in the missing part of the route to the URL, it works.
http://localhost/ProfileAndOrBlog/UserSuggestionMaint/Index
So, why is that route part missing?
I don't quite get your question but it seems your problem is simply about routes.
When using links
<li>#Html.ActionLink("Sign In", "SignIn", "SignIn", routeValues: null, htmlAttributes: new { id = "signinBtn", #class = "btn btn-primary my-signin-btn" })</li>
Simply means it should display "Sign In" on a button and the link will be mapped to something like below:
"/SignIn/SignIn"
and
"/UserSuggestionMaint/Index"
In simple terms routes are usually "/Controller/action" in MVC.
So make sure you are referencing the right action method and it will work.
Using "/UserSuggestionMaint/Index" means the controller should be something like UserSuggestionMaintController and the Index action which will render the Index View.
Something you need to know about using absolute and relative paths in hyperlink <a href>,
Beginning with http:// or //. The browser will resolve the link as an
absolute URL.
Beginning with a single /. The browser will resolve the link as
relative to the domain.
Beginning with text. The browser will resolve the link as relative to
the page.
Beginning with #. The browser will look for an HTML element on the
same page (by ID) and scroll to it if found.
So when you use <a href="/UserSuggestionMaint/Index">, it adds this content after domian not current url.
But when you use #Html.ActionLink, it returns a specified link text according to an anchor element.
In my test, I use #Html.ActionLink in layout page. When I set the MVC application as a separate site, #Html.ActionLink generates a hyperlink likes this:
If I set the MVC applciation as a sub application under a site, it likes this:
Part of /ProfileAndOrBlog url is necessary so that IIS can know which application you want to access. Then asp.net route can know UserSuggestionMaint is controller and index is action.
The solution is:
Not use relative URL of hyperlink but absolute URL. <a href="http://domain name/ProfileAndOrBlog/UserSuggestionMaint/Index">.
Deploy the mvc application as a separate site not a sub application under default web site.
Not use but #Html.ActionLink to dynamically generate a hyperlink.
Thanks all for the insight.
To not change each of the href's to add in the tilde to the beginning of the path as suggested, I instead changed my Publish Profile. I had 'ProfileAndOrBlog' as part of the Site name (Default Web Site/ProfileAndOrBlog) and the Destination URL (http://localhost/ProfileAndOrBlog). I removed it in both places and it resolved the URL problem. Here is how my Publish Profile is now:
I now can successfully access all the functions of my web app when I launch the web site in the browser with this URL: http://localhost
So for my 'Make Suggestions' link, the URL is now: http://localhost/UserSuggestionMaint/Index.
I have an MVC 4 project with a layout page that I have setup with images that are links like this
<img id="logoImage" src="~/Content/siteImages/myLogo.png" alt="My logo" title="Welcome to my site" />
I have also tried this:
<img id="logoImage" src="../Content/siteImages/myLogo.png" alt="My logo" title="Welcome to my site" />
And this:
<img id="logoImage" src="#Url.Content("~/Content/siteImages/myLogo.png")" alt="My logo" title="Welcome to my site" />
These all work fine as long as the controller is the home controller. I use an Actionlink #Html.ActionLink("Northwind Demo", "Northwind", "Northwind", null, new { #class="links"}) to get to another controller.
As soon as the ActionLink is clicked, my images disappear. I examined the rendered link text in the browser and it is the same as it was before.
src="Content/siteImages/myLogo.png"
However, when examining the request in the network tab of the browser the url for the image is now
Northwind/Content/siteImages/myLogo.png
which does not resolve. For some reason the browser is adding the name of the controller to the beginning of the request for the image. I am sure that I am missing something really dumb but...
How do I fix this?
Edit
I wonder if this is an issue that only happens when running locally and may disappear when deployed to a server? I am still unable to fix this.
Edit
I am really struggling with the fact that no one else has encountered this before. I was under the impression that _layout.cshtml was like a master page in WebFroms. I need some suggestions here.
EDIT
So I had a moment of success. I changed the name of the entry method into the Northwind controller to Index and the images displayed properly in the index view. However, if I call another view, then the images disappear again.
I use radion buttons to select a different view based on which one is selected like this:
public ActionResult Search()
{
int id = Convert.ToInt32(Request.Form["radio"]);
switch (id)
{
case 1:
return View("Customer");
case 2:
return View("Orders");
case 3:
return View("Employees");
default:
ViewBag.Error = "Search parameter not found";
return View("Index");
}
}
I am still not able to fix this but I think that I am closer to a solution with someone's help.
Thanks in advance
Don't use relative addressing in MVC, since as you can tell you run into problems because views can be accessed from multiple routes (ie, /, /Home, /Home/Index, etc.. are all the same view, but different paths, if you use ../whatever then /Home/Index becomes /Home/whatever, / and /Home become /whatever)
Always use either #Url.Content to generate urls if you're not in a Razor 2+ view. If you're in Razor 2 or greater, then you can use src="~/Content/images/whatever"
If these methods are not working, then you need to look at your Application root, web.config, etc.. because MVC is becoming confused about where the root of the site is.
Well I have figured this out and I feel like an idiot! I have a script file that I use to change the images when it becomes small enough so that they continue to fit on the screen as it gets smaller for a responsive design. Like this:
$("#logoImage").attr("src", "Content/siteImages/logoSmall.png");
Well, the missing / at the very beginning is what was causing the issue. Adding the / fixed all my issues. Like this:
$("#logoImage").attr("src", "/Content/siteImages/logoSmall.png");
Even though I feel very silly at this moment, I am posting my answer in case someone else comes along and has a similar issue. Don't forget your script files and don't leave anything out when trying to fix a weird issue. Thanks to everyone that looked at this and tried to help.
This view suppose to show a list of hyperlinks, each pointing to an external URL. The goal is for the user to click one of these links and have their browser open a new tab with the selected URL.
Currently I have the following markup:
#Html.ActionLink("SomeSite", "http://subdomain.mydomain.com/SomeSite")
This markup produces:
http://localhost:58980/AccessInstance/http%3a/subdomain.mydomain.com/SomeSite
instead of :
http://subdomain.mydomain.com/SomeSite
What can I change in my markup to make this work as I expect?
You don't need to use #Html.ActionLink for that. Just use a plain A tag:
SomeSite
Html.ActionLink is specifically for generating links to actions defined in MVC controllers, in the same app. Since you're linking to an absolute URL, you don't need any of the functionality that Html.ActionLink provides.
Two ways :
1. update the database column with full link:
eg SQL:
update ProductTable set ProductLink='http://www.example.com/Product/Mobiles' where ID=123
In asp mvc view
View
2. Hardcode the http part and list from model
View
Hope helps someone.
While a ViewBag is overused and not the best choice most of the time this is something that I had done when inheriting someone else's mvc app to do a quick fix for a URL that I needed to redirect to with a specific dynamically changing querystring parameter
<a target="_parent" href="http://localhost:56332/services/#ViewBag.factory">View Service</a>
Using .NET Core 6
This seems to be the most correct answer:
Link
This will generate the following result:
As you can see at the bottom left corner of the window before clicking the link, the URL address was rendered as it is (NOTE: The cursor was recorded out of place for some reason, that's a ShareX problem, ignore it).
Than link will be directly saved as a nvarchar(750) type (probably any character like type will do the work). No changes to the original link were made before saving it or on reading:
You need to take into account your RouteConfiguration.
routes.MapRoute(
name: "Default",
url: "{controller}/{action}"
because you are specifying the action link as the entire link that you want to redirect.
I would recommend that you use the #rossipedia answer because you can make tricky things like putting a span inside the link
Here to display link that are clickable in index page
<td>
#Html.ActionLink(item.FileName, "../Uploads/Catalogue/"+item.FileName)
</td>
am developing an application in which i have to show the customer purchase details supplier wise. for that i have develop user control an add it on page. but the problem it that on user control i need to add a ling to promotional offer page for that supplier which show the current offers of the supplier. for that i have added the hyperlink as fallow to user control
<asp:HyperLink ID="PromoLink" runat="server">Have promo Code ?</asp:HyperLink>
and set the navigation URL as fallow
PromoLink.NavigateUrl = "Promotion.aspx?Filter=" + dt.Rows[0]["SuppId"].ToString();
but when page is load in does not render the navigation url to the link.
i donot why it does not render the url plz help to get out of this.
thanks in advance.
Make sure that the pathing is correct for the NavigateURL property. Try adding "~/" at the start of the NavigateURL or "../" if it is not in the same folder as the current file.
Make sure that the dt.Rows[0]["SuppId"] is actually getting the value that you expect.
Step through code in the debugger to verify that the Page_Load event that you are using is actually executing and modifying the value as you would expect it to.
I have several static files(pages), which are basically copies of my website pages source code, with the content changed.
These files support my website, (keeping the same format) in various ways.
For example the menu part is:-
<body>
<div id="menu">
<ul class="level1" id="root">
etc
etc. until
</ul>
</div>
Unfortunately every month or so my menu bar changes and I have to update each static file manually.
As each of my static files have the same menu.
Is it possible to have one menu file which can be updated and have the static files load them automatically.
I plan to have several more static files. So this would be a great help if someone can suggest how to accomplish this.
Oh yes. Use some javascript magic to load the menu bar upon page load and keep it in menu.html.
One solution may be to use a spider (wget --recursive) to download generated pages directly from your application. One command, and you have the full copy of your site. (just add some useful options, like --convert-links, for example).
The other option may be to write an after_filter in your controller, and write the generated content to a file (not always, but for example when you add a parameter ?refresh_copy=1). Maybe just turning on page caching would be suitable? But the problem will be that you will not be able to trigger the controller action so easily.
If you don't want the whole site copied, just add some specific routes or controllers (/mirrorable/...) and run the spider on them, or just access them manually (to trigger saving the content in the files).
I ended up creating one controller without a model.
rails g controller staticpages
I then created a layout file which imported the individual changes to the layout, via a "yield" tied to a "content_for" in the view files(static files(pages) in the "view of staticpages" (for example abbreviations, aboutthissite etc etc).
The rest of the static file loaded with the usual "yield" in the layout. Works a treat. No more updating the menu bar all done automatically.
To get to the correct static file I created a route using:-
match 'static/:static_page_name'=> 'staticpages#show' (or in rails 2.x:-
map.connect 'static/:static_page_name', :controller=> "staticpages", :action=> "show"
"static_page_name" variable accepted anything after "/static/" in the url and passed it to the controller "staticpages" in which I set up a show action containing:-
def show
#static_page_name = params[:static_page_name]
allowed_pages = %w(abbreviations aboutthissite etc, etc,)
if allowed_pages.include?(#static_page_name)
render #static_page_name
else
redirect_to '/' #redirects to homepage if link does not exists
end
end
I then only had to change the links in the website. (e.g.<%= link_to " About This Site ", '/static/aboutthissite' %>)
and viola! its all working.