Webform in subfolder using master page - c#

Currently all of my web-form files (.aspx) are in root folder of my project (VS 2012).
I created a new folder name "pages" and add a new webform to it (WebForm1), using master page. When I run this page, its address is localhost:49217/pages/WebForm1.aspx which is correct, problems are:
All of links now have been added the word "pages", for example the correct link should be localhost:49217/Contact.aspx now became: localhost:49217/pages/Contact.aspx
The CSS look weird, kind of missing some css files (the path is wrong).
The CSS code in master page, css files are in css folder:
<link rel="stylesheet" href="css/reset.css" type="text/css" media="screen">
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen">
<link rel="stylesheet" href="css/grid.css" type="text/css" media="screen">
If I add a new webform in root folder, everything is fine, but if I do that in a subfolder, everything is messed up.
EDIT:
CSS has been fixed, thanks for everybody.
Still the "pages" not fixed, it is added in all the links (of the master page)

When referencing style sheets or java script files inside of a master page I usually do the following:
<link href="<%= ResolveUrl("~/css/reset.css") %>" rel="stylesheet" />
<script type="text/javascript" src='<%= ResolveUrl("~/js/master.js") %>'></script>
This will work if you are debugging on your local, deploying to a web server in a virtual directory or if you deploy to the website root.

Your paths are relative to the current directory, you need to prefix them with a slash so that they always reference the root directory. Like this:
<link rel="stylesheet" href="/css/reset.css" type="text/css" media="screen">
<link rel="stylesheet" href="/css/style.css" type="text/css" media="screen">
<link rel="stylesheet" href="/css/grid.css" type="text/css" media="screen">
You'll also have to do the same thing to your image paths.

Related

C# WebBrowser not loading local Javascript file

I am using the C# WebBrowser control. My HTML renders fine. However, I need to keep external files on the local computer. References to the local copy of files do not work.
How do I write the HTML to load locally stored files?
This works:
<script type='text/javascript' src='https://code.jquery.com/jquery-latest.min.js'></script>
This works when loading a file directly in to a browser, but not through the C# WebBrowser control:
<script type='text/javascript' src='./jquery-latest.min.js'></script>
Adding the full path gets rid of error messages, but still does not work.
<script type='text/javascript' src='file:///C:/<full path>/jquery-latest.min.js'></script>
I have tried adding this to the first line of the html file which does not solve the problem.
<!-- saved from url=(0014)about:internet -->
Just put your local js file in the same directory with your html file. Then use this will do
<script type='text/javascript' src='./jquery-latest.min.js'></script>

Where point razor folders "_framework" and "_content"?

Where point razor folders "_framework" and "_content"?
_host.cshtml
<script src="_framework/blazor.server.js"></script>
<script src="_content/BlazorInputFile/inputfile.js"></script>
there is no inputfile.js nor a BlazorInputFile folder
simple answer for _content: to wwwroot of those library.
what about _framework? Root directory of library?

What are the mechanics of producing bundled js and css files with master pages?

I have a .NET Core project in which the master page _Layout.cshtml page references site wide style and js files:
<link rel="stylesheet" href="~/css/site.css" />
<script src="~/js/site.js" asp-append-version="true"></script>
The Index.cshtml page, which utilizes the above master page, references page specific style and js files:
<link type="text/css" rel="stylesheet" href="~/css/landing.css">
<script src="~/js/landing.js" asp-append-version="true"></script>
And then Contact.cshtml and About.cshtml also have page specific css and js files.
What is the correct method to bundle the site wide files with page specific files?
Should I avoid referencing anything the in the master page and simply reference the bundled file in each page's .cshtml?
You reference in your Master Page all scripts and Style Sheets you share across pages. For instance, you could reference only jquery.
You reference in your pages scripts and styles that are used specific on that pages.
It sounds simple like that.

Asp.net: relative paths not working when deployed IIS

I spent almost 2-3 good hours on this and im here now, as the question states. The project works fine in VS but when I deploy/publish it through IIS (to access it on local network) some files (well most of them) aren't accessible. This happened when I added the Metronic theme within my web project. The files are like:
<!-- BEGIN GLOBAL MANDATORY STYLES -->
<link href="http://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700&subset=all" rel="stylesheet" type="text/css" />
<link href="../../assets/global/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
<link href="../../assets/global/plugins/simple-line-icons/simple-line-icons.min.css" rel="stylesheet" type="text/css" />
<link href="../../assets/global/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<link href="../../assets/global/plugins/bootstrap-switch/css/bootstrap-switch.min.css" rel="stylesheet" type="text/css" />
<!-- END GLOBAL MANDATORY STYLES -->
OR
<img src="../assets/pages/img/logo.png" alt="place Logo Here" />
Now once its published, it throws me a pile of errors that it could not find any of those files.
Notice: the url in both the pictures, the deployed project is under another folder. is it the culprit?
I am trying to figure out a solution that works for both VS debugging and the deployed project.
What I have tried is:
1: https://weblogs.asp.net/scottgu/tip-trick-how-to-run-a-root-site-with-the-local-web-server-using-vs-2005-sp1
2: Deploying asp.net application to root directory in IIS
3: How to avoid deploying ASP.NET MVC3 application in subpath on IIS 7.5
4: ASP.NET WebForms: Why do relative paths within user controls work locally, but not when deployed?
5: IIS virtual directory and ASP.NET directory paths
6: Relative path from site root
You might want to use absolute paths starting with '~/' as the base directory of your Web Site / Web App.
e.g. "~/assets/pages/img/logo.png"
and when working in Code Behind use the
Server.MapPath("~/")
as Base Folder.
g2 is the folder that I created inside wwwroot which has the published files
If your intent was to make that a "sub application" (of whatever is the "parent" in wwwroot then it can be a "virtual directory" or a "sub application"
If your intent was to publish it as it's own application, separate from any other, then you don't have to publish it under wwwroot. You create new IIS sites.
The previous answer using ~/ is based on what is defined as the application root
Hth...

Localization on _Layout.cshtml

I'm trying to apply localization on _Layout.cshtml
_Layout.cshtml
#using Microsoft.AspNetCore.Http.Extensions
#using Microsoft.AspNetCore.Localization
#using Microsoft.AspNetCore.Mvc.Localization
#inject Microsoft.ApplicationInsights.AspNetCore.JavaScriptSnippet JavaScriptSnippet
#inject IViewLocalizer LayoutLocalizer
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div style="margin:38px;margin-top:56px;" class="hidden-sm-down">
<h2>#LayoutLocalizer["WelcomeHeader"] <b class="text_border_darkblue">MyTitle</b></h2>
<div style="text-align:center;margin-top:42px;">
#LayoutLocalizer["WelcomeSub"]
</div>
</div>
</body>
</html>
The resource files are named named: Views.Shared._Layout.no.resx (I've tried renaming to views.shared.Layout.no.resx without any luck)
You must create a _Layout.no.resx file within the same path of the views but as a root the "Resources" folder. See sample image:
There is a video clarifying the use of Location see here
Solution
Implement SharedResources with resource files and use Localization on
the SharedResources object in shared Views
You can combine IViewLocalizer and IHtmlLocalizer for _Layout.cshtml. If you define a resource folder inside your Visual Studio solution you can put the resource files there.
If you are using razor pages instead of MVC views inside your ASP.net core application you create a subfolder Pages instead of Views inside the folder Resources. Put the _Layout.no.resx file in there. e.g. Resources\Pages\_Layout.no.resx.

Categories