Is there any template based system available for .net? I have several domains i want to handle them using a single system. Each domain can have different design. But all will be manage through a single management system.
Assuming that you mean that you want your app to select it's CSS and images folder dynamically based on the host name (domain name) in the request in order to skin your app based on the domain name, you could try something like this:
public static class Skin
{
public static string Url(string assetPath)
{
var host = System.Web.HttpContext.Current.Request.Url.Host;
switch (host)
{
case "www.myfirstsite.com":
return UrlPath("~/Content/myfirst/" + assetPath.TrimStart('/'));
case "www.theothersite.com/":
return UrlPath("~/Content/theother/" + assetPath.TrimStart('/'));
default:
return UrlPath("~/Content/default/" + assetPath.TrimStart('/'));
}
}
private static string UrlPath(string virtualPath)
{
return VirtualPathUtility.ToAbsolute(virtualPath);
}
}
Which would make all your views look something like this when referencing CSS and images:
<%# Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>My Page</title>
<link rel="stylesheet" type="text/css" href="<%= Skin.Url("css/master.css") %>" />
</head>
<body>
<img src="<%= Skin.Url("images/myimg.gif") %>" alt="myimg" />
</body>
</html>
Related
Controller Class
#RequestMapping(value = "/")
public String indexmethod(){
return "index";
}
css file location : \src\main\resources\static\index.css
jsp file:
<%# taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %>
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<link href="/index.css" rel="stylesheet">
<title></title>
</head>
<body>
<div>
<h2>cascascascascas</h2>
</div>
</body>
</html>
Try this:
<link href="${pageContext.request.contextPath}/index.css" rel="stylesheet">
Found the Solution. A specific #requestmapping(value="...") option in
Controller class block the static file.. I just delete that specific
#reqestmapping and after that i get access to static folder. I am
keeping this question. So that, it can help other to solve same
problem.
My project tree looks like this:
I can access the templates now, but can't load static resources such as CSS, images, and JS.
I have a common.html fragment where I declare all my static resources, for instance:
<link rel="stylesheet" th:href="#{/css/app.css}"/>
A header fragment where I include common.html like so:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head th:include="fragments/common :: commonFragment" lang="en"></head>
// page body
</html>
A default.html file for layout:
<!DOCTYPE html>
<html lang="en"
xmlns:th="http://www.thymeleaf.org"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head th:include="fragments/common :: commonFragment" lang="en">
<meta charset="utf-8"/>
<meta name="robots" content="noindex, nofollow"/>
<title>Touch</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta http-equiv="content-dataType" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta name="apple-mobile-web-app-capable" content="yes"/>
<link rel="shortcut icon" th:href="#{/static/images/favicon.ico}" type="image/x-icon" />
</head>
<body>
<div th:id="defaultFragment" th:fragment="defaultFragment" class="container">
<div id="header" th:replace="fragments/header :: headerFragment" />
<div layout:fragment="content" />
</div>
</body>
</html>
Also, on my application.properties file, I have these entries:
#SPRING RESOURCE HANDLING
spring.resources.static-locations=classpath:/resources/
#THYMELEAF
spring.thymeleaf.cache = true
spring.thymeleaf.check-template = true
spring.thymeleaf.check-template-location = true
spring.thymeleaf.content-type=text/html
spring.thymeleaf.enabled=true
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.mode=HTML5
spring.thymeleaf.prefix=classpath:templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.template-resolver-order=1
But I keep getting the same No mapping found message.
32190 [http-nio-8081-exec-2] WARN o.s.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/central/css/app.css] in DispatcherServlet with name 'dispatcherServlet'
What am I not seeing here?
I solved this problem with the following code:
spring.resources.static-locations=classpath:templates/
Use the spring.resources.static-locations in your properties to define the static resources locations (making them directly publicly available):
spring.resources.static-locations=classpath:/your/static/resources/here/like/central/css/
you can provide comma separated values i.e. taken from the documentation:
spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/ # Locations of static resources.
I'm using Spring Boot 2.2 and not getting any of my static content. I discovered two solutions that worked for me:
Option #1 - Stop using #EnableWebMvc annotation
This annotation disables some automatic configuration, including the part that automatically serves static content from commonly-used locations like /src/main/resources/static. If you don't really need #EnableWebMvc, then just remove it from your #Configuration class.
Option #2 - Implement WebMvcConfigurer in your #EnableWebMvc annotated class and implementaddResourceHandlers()
Do something like this:
#EnableWebMvc
#Configuration
public class SpringMVCConfiguration implements WebMvcConfigurer {
#Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/js/**").addResourceLocations("classpath:/static/js/");
registry.addResourceHandler("/css/**").addResourceLocations("classpath:/static/css/");
registry.addResourceHandler("/vendor/**").addResourceLocations("classpath:/static/vendor/");
registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
}
}
Just remember that your code is now in charge of managing all static resource paths.
try to add mapping of your static resources in link
<link rel="stylesheet" th:href="#{/css/app.css}"
href="../../../css/app.css" />
iv added a new folder inside my 'customPages' folder 'Check' i've then added a new webform page inside the 'check' folder called 'show'
<%# Page Language="C#" AutoEventWireup="true" CodeFile="show.aspx.cs" Inherits="DynamicData_CustomPages_Check_show" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
bla bla la
</div>
</form>
</body>
</html>
when I try to navigate it from another page it wont work ERROR: 28889/CRC/Check/show.aspx
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /CRC/Check/show.aspx
any idea as to why?
EDIT:iv even set it as my start page my right clicking, but it still cant find the page?
You said that you added a WebForm called List, so instead of show.aspx, you should try list.aspx.
If your new folder is in your custompages folder than url shoould be like this
YourApplication/customPages/Check/show.aspx
I think you are missing customPages folder
Open Global.asax
There should be something like this:
routes.Add(new DynamicDataRoute("{table}/{action}.aspx") {
Constraints = new RouteValueDictionary(new { action = "List|Details|Edit|Insert" }),
Model = model
});
Add 'Show' in the action list.
I have the following page that references my silverlight application file. This works fine. I was wondering if, instead, I could point to a specific xaml file that is in the .xap file?
Perhaps something like /ClientBin/test.xap?File=SomeXaml.xaml?
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="test.Web.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="Silverlight.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div id="silverlightControlHost">
<script type="text/javascript">
Silverlight.createObject(
"ClientBin/test.xap", // source
document.getElementById('silverlightControlHost'), // parent element
"someId", // id for generated object element
{
width: "600px",
height: "600px",
background: "blue",
version: "4.0.60310.0",
autoUpgrade: "true"
},
{ onError: null }, null
);
</script>
</div>
</form>
</body>
</html>
Thanks!
First of all see my answer here to a very similar request that does most of what you need.
All you now need is to get the xaml file name from the query string to the initparams. Your existing code would become:-
Silverlight.createObject(
"ClientBin/test.xap", // source
document.getElementById('silverlightControlHost'), // parent element
"someId", // id for generated object element
{
width: "600px",
height: "600px",
background: "blue",
version: "4.0.60310.0",
autoUpgrade: "true"
},
{ onError: null }, 'StartupPage=<%=Request.QueryString[File]%>'
);
The project I'm working on allows an end-user to modify CSS code to integrate the application as best possible. Most of the CSS values are stored in a database and need to be retrieved and parsed dynamically.
I setup a Style controller, and gave each stylesheet an action, and then passed the configuration data through to the View. I set the ContentType to "text/css" and then generated the stylesheets.
This works fine, but the problem I'm running into is this: none of the code works in the application. I include it in the head code, but it doesn't parse in the code.
An example of what I do is this:
<%# Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" ContentType="text/css" %>
.element {
background-color: <%= ViewData.Model.BackgroundColor %>;
}
I include it like so:
<link href="/style/Basic" rel="stylesheet" type="text/css" media="all" />
When I include the CSS code in a partial view and include it using the ViewModel (wrapped in style tags) in an action, then everything works fine. It is when I try to parse this as a separate file when it does not work.
Is there something I am doing incorrectly? Or is there some kind of glitch?
Thanks in advance :D
Use a tool such as HTTPWatch to verify that the stylesheet is being sent down and not 404'd
Controller
public ActionResult Basic()
{
Response.ContentType = "text/css";
var basicVM = new BasicVM()
{
BackgroundColor = "Lime",
};
return View(basicVM);
}
And the View
<%# Page Language="C#" Inherits="System.Web.Mvc.ViewPage<MvcApplication3.Controllers.BasicVM>" ContentType="text/css" %>
body {
background-color: <%= ViewData.Model.BackgroundColor %>;
}
and the test page
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Test</title>
<link href="/Home/Basic" rel="stylesheet" type="text/css" media="all" />
</head>
<body>
<div>
Test
</div>
</body>
</html>
Turns everything Green