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>
Related
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");
}
}
I have integrated SagePay's 'Drop In Checkout' into a test solution. The issue is, when I am submitting the form for the 'cardIdentifier', it is returned in the URL as a QueryString, rather than a hidden field, as per the documentation.
http://integrations.sagepay.co.uk/content/getting-started-integrate-using-drop-checkout
"Once the customer initiates the form submission, the payment details are validated, tokenised and passed as a hidden field called cardIdentifier which is then posted with the rest of the form contents"
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="CustomPayment.aspx.cs" Async="true" Inherits="SagePayDropInTest.CustomPayment" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="https://pi-test.sagepay.com/api/v1/js/sagepay-dropin.js"></script>
</head>
<body>
<div id="main">
<h1>My Test Shop</h1>
<form id ="checkout-form">
<h2>Payment Details</h2>
<div id="payment-details"></div>
<div id="submit-container">
<input type="submit"/>
</div>
</form>
</div>
<script>
sagepayCheckout({
merchantSessionKey: '<%=MerchID%>',
containerSelector: '#payment-details'
}).form({
formSelector: '#checkout-form'
});
</script>
</body>
</html>
C# CodeBehind
namespace SagePayDropInTest
{
public partial class CustomPayment : System.Web.UI.Page
{
public string MerchID = "";
protected void Page_Load(object sender, EventArgs e)
{
MerchID = GetMerchSessionID();
}}}
It does return the cardIdentifier, but just as a QueryString, but I would rather I was getting it as a hidden-field, as documented. The rest of the integration works as documented, it is just this step which is throwing me.
I am no doubt missing something obvious, and any guidance would be much appreciated.
Try changing the <form> tag to include a method="post" attribute. This should mean that the cardIdentifier is sent as a posted field rather than in the query string. The default method for a form is normally a GET request, the SagePay JS probably doesn't change this.
Also, there looks like an extra space in the <form id ="checkout-form"> tag as it is. I would recommend taking this out as some less forgiving browsers may not parse this correctly, breaking the CSS selector in your JS.
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
Hi i have a question about Session variables, i want to call in GET via ajax, from my .aspx page, a page .asp that have VB6 code inside, i need to share Session variables between them actually i tried this:
ASPX file
<html>
<head>
<title>let's try Ajax</title>
<script type="text/javascript" src="Scripts/jquery-1.10.2.js"></script>
<script>
$(document).ready(function () {
var request = $.ajax({
url: "/Default.asp",
type: "GET",
dataType: "html",
cache: "false"
});
request.done(function(msg){
$("#insert").html(msg);
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
in the aspx: <%Response.Write(Session["try"].ToString()); %>
</div>
<div id="insert">
</div>
</form>
</body>
</html>
code behind page:
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
Session["try"] = "hello world";
}
}
finally .asp page
<%
[...]
Response.Write "" & Session("try")
Response.End
[...]
%>
Actually the Session doesn't show anything in the .asp page, but in the .aspx page shows it's string inside, what's wrong with my code? Is it possible to pass share a session?
I think, you want to share your session between Class ASP and ASP.Net. so you need to store
your session information in SQL server. Please refer below link
http://msdn.microsoft.com/en-us/library/aa479313.aspx
I am getting the error on the below code in asp.net 4.0
<script type="text/javascript" src='<%#=ResolveUrl("~/Scripts/jquery-1.4.1.js")%>'></script>
Error Message: CS1525: Invalid expression term '='
I am using this code in Site.Master in head tag
You can't use <%# and <%= at the same time. Try it like this:
<script type="text/javascript" src='<%= ResolveUrl("~/Scripts/jquery-1.4.1.js")%>'></script>
EDIT
If you are getting an error that states:
The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
when you try to use <%= ResolveUrl(..., it is because something in your code is attempting to add controls to your header control in Site.Master. If that is the case, switch the script tag to read:
<script type="text/javascript" src='<%# ResolveUrl("~/Scripts/jquery-1.4.1.js")%>'></script>
and make sure you call the DataBind() method on the header tag at some point (for example, from the Page_Load method for Site.Master):
public partial class SiteMaster : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
Page.Header.DataBind();
}
}
You can use ResolveUrl with Eval like this. No external code needed.
<img src='<%# ResolveUrl(Eval("FILE_URL").ToString()) %>' alt=""
style="width:50px;height:50px"/>