I have created an MVC project in ASP.NET 4.5 and designed the index page of home controller using bootstrap. When I browse to the url
http://localhost:59772/,
it gets rendered perfectly. But when I go to
http://localhost:59772/Home/Index,
which is essentially the same page, bootstrap doesn't gets rendered and everything appears as plain text without any styling. I have properly set the default values in route config as
Controller = home, action = Index
. Any help is appreciated.
The links are searched for in the current directory you are browsing. If you are on
localhost:12345/
It will look for resources in the project folder and if you are browsing
localhost:12345/home/index
It will look for resources in home folder, even though both the url's render the same page. Thats why bootstrap etc doesn't gets loaded the second time.
Related
I know this has been asked before but I haven't seen any simple explanations and I should also add I'm on shared hosting (Plesk). I don't see the URLRewriter utility installed on the server.
Anyway, I rebuilt my 2013 website that did use ASP.NET web forms (with .ASPX extensions). I'd like to be able to redirect my old pages to their new equivalents. i.e.
https://www.findaforum.net/diyfishkeepers-com.aspx
Should now point to:
https://www.findaforum.net/Forums/diyfishkeepers-com/
At the moment the .ASPX pages show this in a red box on a yellow screen:
XML Parsing Error: no element found
Location: https://www.findaforum.net/diyfishkeepers-com.aspx
Line Number 1, Column 1:
Where does this "come" from?
Incidentally, I'm looking for a quick and easy fix because I don't have too many external links pointing to my site's subpages, but it would be nicer for the user experience to fix it while Google works out I've changed my entire site.
This answer basically works:
How to redirect .ASPX pages to .NET Core Razor page
There's a good link to the URL rewriting regular expressions here: https://isitoktocode.com/post/introduction-to-url-rewriting-using-iis-url-rewrite-module-and-regular-expressions
This is what I've put in Startup.cs:
var options = new RewriteOptions()
.AddRedirect(#"ShowCategories.aspx", "/Home/Categories/")
.AddRedirect(#"Statistics.aspx", "/Home/TopForums/")
.AddRedirect(#"SubmitForum.aspx", "/Home/Submit/")
.AddRedirect(#"Help.aspx", "/Home/HelpAndFAQ/")
.AddRedirect(#"([0-9a-z-A-Z]+)(.aspx)", "/Forums/$1/");
app.UseRewriter(options);
Note: Make sure you put the specific ones at the top, then the generic ones at the bottom.
I also had some URLs like https://www.findaforum.net/lpsg-com where 'lpsg-com' is a forum name. I added a URL to the home controller to take care of these...
[HttpGet]
[Route("{code}")]
public ActionResult Unknown(string code)
{
return RedirectToAction(code, "Forums");
}
I am creating a new asp.net web application.
Application contains a default master page i.e site.master.
That Master page has link to site .css that was the by default css attached.
link href="~/Styles/Site.css" rel="stylesheet" type="text/css"
I removed site.css from my project(exclude from project) but its functionality survive. How this is happening? Why the styles gets not deleted or removed??
I am Using IE11.
Exclude from Project is not good way to do this.
Remove that file completely then you will not have that file loaded.
after that remove reference from master page or anywhere you are giving it.
Do CTRL + SHIFT+ F for entire solution search and search for that file name. so remove that references if you find.
now about browser cache issue. remove browser cookies and history. Or you have one more option like open your website and load with b y pressing
CTRL + F5. it will load your website totally fresh and with new code completely.
I'm having the following problem in my application.
When access a view, specifying only the controller, the entire layout of the master page is rendered correctly:
Eg:
localhost:50904/Contact
But when I specify the action, the layout of the master page is not rendered:
Eg:
localhost:50904/Contact/Index
localhost:50904/Contact/Success
I checked the HTML generated in both cases, and the generated HTML is correct. What can I be doing wrong?
Possibly you have references to .css files and those references are relative. Change the references to the .css files to start with / to make them rooted to the root of the site.
Press F12 and look for any errors in the console or network tabs.
You my find that the css or js files are not loading, check the paths if you see any errors.
I have a wordpress-driven project and want to add 1 single page to that project, that has entirely nothing to do with wordpress at all, but just consists of plain html - no links from the one to the other; nothing. This page shall be accessible via abc.com/folder while the original wordpress-project is still all over abc.com
What would be the best way to do this? Just add the folder and page, or do I also need to do something on the htaccess-file?
thanks
Just create that folder and name your html index.html inside that folder. This way that html file can be accessed via abc.com/folder
I am writing a web page to show image (image is dynamically generate by .Net charting) in a web. I have used the asp.net web forms URL routing to navigate to this page. Once I use the URL routing the image appear on the page. Anyway this is working fine for normal page browse.
More than likely your link to the image is using a relative path, and once you introduce routing you are working with a URL structure that appears to be deeper nested in the folder structure than it is.
When linking to the image for display I would recommend using root relative path something like /Images/MyFile.jpg rather than ../Images/MyFile.jpg, or similar.
This way if your route changes, and additional "folders" appear in the route, the link will still work.