Asp.net #Include external files in content - asp.net

I have an asp.net application using MasterPages. In the master page I am using Include to incorporate external content.
<%# Master Language="C#" AutoEventWireup="true" CodeBehind="ResponsiveContentEmpty.master.cs" Inherits="WebUI.MasterPages.ResponsiveContentEmpty" %>
<!DOCTYPE html>
<html lang="en-us" class="theme-indigo">
<head>
<!--#include file="https://www.xxx.gov/TemplatePackage/4.0/includes/head-content.html" -->
<title>Home | aaa| xxx</title>
</head>
When the page runs I get:
Server Error in '/' Application.
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: The given path's format is not supported.
Source Error:
Line 4: <html lang="en-us" class="theme-indigo">
Line 5: <head>
Line 6: <!--#include file="https://www.xxx.gov/TemplatePackage/4.0/includes/head-content.html" -->
Line 7: <title>Home | aaa| xxx</title>
Line 8: <link
The goal is to include this external content. What am I doing wrong ?

You cannot inlcude files from another website. If you really want to do that, download that content and inject it in the header.
So place a Literal in the Head of the Master Page.
<head runat="server" id="Head1">
<title>Test</title>
<asp:Literal ID="Literal1" runat="server" EnableViewState="false"></asp:Literal>
</head>
Then in Page_Load
protected void Page_Load(object sender, EventArgs e)
{
using (var client = new WebClient())
{
Literal1.Text = client.DownloadString("https://www.xxx.gov/TemplatePackage/4.0/includes/head-content.html");
}
}

Related

jasper report to pdf conversion error using jsp. It shows failed to load pdf

this is my project viewer screenshot
Search.jsp
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h3>Search the id which you want</h3>
<form method="POST" action="filereport.jsp">
<p>Give the searching ID</p>
<input type="text" name="employid"/><br>
<input type="submit" value="show"/>
</form>
</body>
</html>
filereport.jsp
<%#page import="java.sql.SQLException"%>
<%# page import="java.io.*"%>
<%# page import="java.sql.Connection"%>
<%# page import="java.sql.DriverManager"%>
<%# page import="java.util.HashMap"%>
<%# page import="java.util.Map"%>
<%# page import="net.sf.jasperreports.engine.*"%>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%#page import="Class.*" %>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h2>your searching result is :</h2>
<%
Connection conn=null;
try{
//connection to mysql database
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/product?user=root&password=mysql123");
////Loading Jasper Report File from Local file system
String jrxmlFile = session.getServletContext().getRealPath(request.getContextPath())+"/Reports/reportgenerate.jasper";
InputStream input = new FileInputStream(new File(jrxmlFile));
Map parameters = new HashMap();
int id=Integer.parseInt(request.getParameter("employid"));
parameters.put("employeeid", id);
//generating the report
JasperReport jasperReport = JasperCompileManager.compileReport(input);
JasperPrint jasperPrint=JasperFillManager.fillReport(jasperReport, parameters,conn);
//byte[] bytes = JasperRunManager.runReportToPdf(reportFile.getPath(), parameters, conn.getconnection());
//exporting the report as pdf
//
////Exporting the report as a PDF
JasperExportManager.exportReportToPdfStream(jasperPrint, response.getOutputStream());
}catch(FileNotFoundException e){
e.printStackTrace();
}catch(JRException e){
e.printStackTrace();
}catch(ClassNotFoundException e){
e.printStackTrace();
}catch(SQLException e){
e.printStackTrace();
}finally{
if(conn!=null){
conn.close();
}
}
%>
</body>
</html>
he problem is when i run the file a blank pdf view opens and shows an error "Failed to load pdf document". Can anybody help please?
Thanks in advance.
I can see two issues:
You should flush and close response.getOutputStream()
Example
JasperExportManager.exportReportToPdfStream(jasperPrint, response.getOutputStream());
response.getOutputStream().flush();
response.getOutputStream().close();
Consider to use try catch statements for close(), and also to add correct headers for your response.
If the report datasource is empty and you do not have attribute whenNoDataType on your jasperReport tag, it will generate an empty pdf, that may cause troubles. You can change this behaviour setting the whenNoDataType="BlankPage" or whatever you see most fitted. see WhenNoDataTypeEnum API

Trying to get a response from xml on an iis7 server

I'm trying to display the version info in a web page on an IIS7 server. I really have no clue what I'm doing, but I would like this to be processed server side, and I'm assuming that means using some variation of asp. I know how to use php to do something similar, but that's not an option for this project. The xml document is coming from a local resource on the same server using the following url:
https://127.0.0.1:8443/webservice/rm-agent/v1/monitor/devices?scope%3Dequipment
and the output of the in chrome looks like this:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<DEVICES count="3" time="13-10-12 16:29:20">
<VIEW name="all" scope="equipment">
<DEVICE mac_address="88:E0:F3:20:08:B9" model="WLC2" system_ip="192.168.1.99/24" sw_version="8.0.3.6.0" location="""" name="WLC2" license="WLAN Access Points:4Adv Voice:1Mesh/Bridging:4High-Availability:1Spectrum Analysis:4" object-id="com.trapeze.appl.shared.mdl.Chassis: 28660" contact="" serial_number="KE3211500127"/>
<DEVICE mac_address="f8:c0:01:ab:54:c0" model="WLA532-US" system_ip="192.168.1.75" name="name-WLA1" object-id="com.trapeze.appl.shared.mdl.DistributedAP: 29143" serial_number="jb0212039600">
<RADIOS_INFO radio_1_type="802.11ng" radio_2_mac_address="f8:c0:01:ab:54:c1" radio_2_type="802.11na" radio_1_mac_address="f8:c0:01:ab:54:c0"/>
</DEVICE>
<DEVICE mac_address="ac:4b:c8:02:68:00" model="WLA532-US" system_ip="192.168.1.82" name="WLA9999" object-id="com.trapeze.appl.shared.mdl.DistributedAP: 167425" serial_number="jb0212294341">
<RADIOS_INFO radio_1_type="802.11ng" radio_2_mac_address="ac:4b:c8:02:68:01" radio_2_type="802.11na" radio_1_mac_address="ac:4b:c8:02:68:00"/>
</DEVICE>
</VIEW>
</DEVICES>
I really just need an html page that shows the sw_version from the first response element, so it would basically just be a page that says:
8.0.3.6.0
Another problem is that I'm forced to use a https url to request the info, but I don't have the ability to install a proper certificate, so the certificate needs to be ignored as well.
this is what I have tried so far:
<%# Page Language="C#" %>
<%# Import Namespace="System.IO" %>
<%# Import Namespace="System.Xml" %>
<%# ServicePointManager.ServerCertificateValidationCallback = delegate( object s, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors ) { return true; }; %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
string url = #"https://127.0.0.1:8443/webservice/rm-agent/v1/monitor/devices?scope%3Dequipment";
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(url);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<pre>
<asp:Literal ID="lit1" runat="server" />
</pre>
</div>
</form>
</body>
</html>
I can't get the load to ignore the certificate warning, and I get a parse error on that line.
Thanks #John Saunders for the help getting the request to ignore the certificate warning.
I was unable to get the XML to parse, I think because it was in a weird format from the source, or more likely because I have no clue what I'm doing, but I got it working, so that's all I care about :D
Here is the code that I finally used:
<%# Page Language="C#" %>
<%# Import Namespace="System.IO" %>
<%# Import Namespace="System.Xml" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate( object s, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors ) { return true; };
string url = "https://127.0.0.1:8443/webservice/rm-agent/v1/monitor/devices?scope%3Dequipment";
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(url);
string xmlString = xmlDoc.OuterXml;
string testString = Regex.Match(xmlString, #"sw_version=""([^)]*)"" location").Groups[1].Value;
Response.Write("<center><h2>The Current Version Is:</h2><h1>"+testString+"</h1></center>");
}
</script>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Version</title>
</head>
<body>
</body>
</html>

asp.net dynamic data NEW custom page ERROR NOT FOUND

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.

ASP.NET MVC Dynamic Stylesheets

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

Any Asp.net or Asp.net MVC template based system?

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>

Resources