Loading a non-MVC intranet webpage in MVC View - html

We have an old custom asp intranet site in which we access our internal databases and I've managed to setup a html page to be able to load other intranet sites like ccnet, wiki etc using <iframe /> tags, via the static menu on top of the page.
Example legacy code:
Menu.asp:
<body topmargin="0" and leftmargin="0">
<div id="header">
<a href="default.asp" id="logo">
<img src="Images/Home.png" alt="Bam! Home" width="40" height="40"/>
</a>
<ul id="NavMenu">
<li><a>DB tasks</a>
<ul>
<li>Restore .bak</li>
<li>Restore .sqb</li>
<li>Create Snapshot</li>
<li>Revert to Snapshot</li>
<li>Delete Snapshot</li>
</ul>
</li>
<li><a>General</a>
<ul>
<li>Wiki</li>
</ul>
</li>
</ul>
</div>
ccnet.asp (to load the intranet page in an iframe to retain the menu):
<!-- #include file = "common.asp" -->
<html>
<head>
<title><%
'Common DB tasks:
if Request("Target") = "CreateDbSnapshot" then
Response.write "Create Db Snapshot"
elseif Request("Target") = "RevertToDbSnapshot" then
Response.write "Revert To Db Snapshot"
elseif Request("Target") = "DeleteDbSnapshot" then
Response.write "Delete Db Snapshot"
elseif Request("Target") = "RestoreBak" then
Response.write "Restore Bak"
elseif Request("Target") = "RestoreSqb" then
Response.write "Restore Sqb"
'General
elseif Request("Target") = "Wiki" then
Response.write "Wiki"
'Final just incase there is an unavailable option:
else
response.write "DBServer CCNet"
end if
%></title>
<link rel="stylesheet" type="text/css" href="common.css"/>
</head>
<!--#include file ="menu.asp"-->
<body>
<%
dim iFrameTargetSrc
'Common DB tasks:
if Request("Target") = "CreateDbSnapshot" then
iFrameTargetSrc = "http://DBServer/ccnet/server/local/project/1.%20Create%20DB%20Snapshot/ViewProjectReport.aspx"
elseif Request("Target") = "RevertToDbSnapshot" then
iFrameTargetSrc = "http://DBServer/ccnet/server/local/project/3.%20Delete%20DB%20Snapshot/ViewProjectReport.aspx"
elseif Request("Target") = "DeleteDbSnapshot" then
iFrameTargetSrc = "http://DBServer/ccnet/server/local/project/FS%20Backup%20SQB/ViewProjectReport.aspx"
elseif Request("Target") = "RestoreBak" then
iFrameTargetSrc = "http://DBServer/ccnet/server/local/project/Restore%20DB/ViewProjectReport.aspx"
elseif Request("Target") = "RestoreSqb" then
iFrameTargetSrc = "http://DBServer/ccnet/server/local/project/Restore%20SQB/ViewProjectReport.aspx"
'General
elseif Request("Target") = "Wiki" then
iFrameTargetSrc = "http://wiki/sites/CompanyWiki/SitePages/newhome.aspx"
'Final just incase there is an unavailable option:
else
iFrameTargetSrc = "http://DBServer/ccnet/ViewFarmReport.aspx"
response.write "Cannot find requested target " & Request("Target") & "."
end if
%>
<iframe src="<%response.write iFrameTargetSrc%>" seamless="true" frameborder="0" width="100%" height="94%"></iframe>
</body>
</html>
We've started to convert this legacy intranet site to MVC5, but what I can't figure out is how to be able to create a view that can load the ccnet and other intranet site pages in a view which spans the whole page when selecting the link from the menu. Views need the data from the controller. How should I pass the information to the controller and load the view containing the non-mvc intranet site?
I'm trying to add the menu option to the _Layout.cshtml page, but haven't found anything that can point me in the right direction of how to implement this.
Any advice, containing a link that can show me how by using examples or solutions posted here will be highly appreciated.

You can add an action method to a controller like this
public ActionResult LoadExternalSystem(string identifier)
{
switch (identifier.ToLower())
{
case "wiki":
{
ViewBag.LoadUrl = "http://wiki.somewhere";
break;
}
case "othersystem":
{
ViewBag.LoadUrl = "http://othersystem";
break;
}
}
return View();
}
Then create a view for that action that looks like the following
#{
ViewBag.Title = "LoadExternalSystem";
}
<iframe src="#ViewBag.LoadUrl"></iframe>
Then use the following for your menu
<ul>
<li>wiki</li>
<li>Other system</li>
</ul>

Related

How to display Success message after clicking Save in HTML page

I have an html form containing this code which runs on IIS:
<form action="http://server1/data.asp" method="POST">
Your Name: <input name="name" type="text">
<input value="Save" type="submit">
</form>
After user submits this form it runs the code in data.asp which displays a Success message with code to write to a text file (file1.txt):
Success!
<%
Dim fso
Dim tst
Set fso=Server.CreateObject("Scripting.FileSystemObject")
Set tst = fso.OpenTextFile("C:\Inetpub\wwwroot\data\file1.txt", 8, true)
tst.writeline "Name = " & Request.Form("name")
tst.writeline "" & Request.Form("")
tst.close
Set tst = Nothing
Set fso = Nothing
%>
This works but it just shows a page with Success! and stays there. What I'd really like is:
After user submits the form by clicking Save I'd like a little message box that says "Success" and remain on the same html page or go to a url I specify within the code.
I don't want to use Java or 3rd party extensions. This is an HTML page that runs the data.asp page on submit and I'd like it to stay that way if possible.
So how would I modify the html and/or data.asp page to do this?
You can do like this:
Response.Redirect "https://www.yoursite.com/thankyou.asp"
Instead of returning "Success!" as your response content you can return the form content you have above, this way you can use the same file for the GET and POST methods, with an condition on your asp logic to execute only on POST requests and return a success alert when the code is excuted successfully.
<form action="http://server1/index.asp" method="POST">
Your Name: <input name="name" type="text">
<input value="Save" type="submit">
</form>
<%
If (Request.Method = "POST") Then
Dim fso
Dim tst
Set fso=Server.CreateObject("Scripting.FileSystemObject")
Set tst = fso.OpenTextFile("C:\Inetpub\wwwroot\data\file1.txt", 8, true)
tst.writeline "Name = " & Request.Form("name")
tst.writeline "" & Request.Form("")
tst.close
Set tst = Nothing
Set fso = Nothing
response.write ("<script>alert('Success!');</script>")
End If
%>
Found the solution by adding an extra page to the mix (redir2form.asp):
in data.asp:
<%
Dim fso
Dim tst
Set fso=Server.CreateObject("Scripting.FileSystemObject")
Set tst = fso.OpenTextFile("C:\Inetpub\wwwroot\data\file1.txt", 8, true)
tst.writeline "Name = " & Request.Form("name")
tst.writeline "" & Request.Form("")
tst.close
Set tst = Nothing
Set fso = Nothing
%>
Response.Redirect "http://server1/redir2form.asp"
in redir2form.asp:
<%
response.write ("<script>alert('Success!');</script>")
%>
<meta http-equiv="refresh" content="1; url=http://server1/index.htm" />
Index.htm has the form action going to the data.asp page.
Not as neat as it could be but that's how I got it to work. After a user submits the form he gets the "Success!" message box and once they click OK they're redirected back to the form page.

Calling a vbscript funciton to update a SQL table from an HTML form generated on an asp-classic page

Having a hard time with updating a SQL table from an HTML form generated on an asp-classic page. The page dynamically creates a table based on a SQL query; I've added a form for the purpose of editing certain fields displayed in the table but have been unable to trigger the function (i.e. onclick) that the form button calls using the code below. I've tried multiple variations of the syntax used for calling the function via VBscript and am missing something entirely. I'm wondering if I'm trying something that can't be done in the asp-classic environment due to the server side code being used and the limitations that go with that (as well as my trying to use the same page to generate the results). I know the default behavior for the form is to refresh the page if I don't specify a different page. In the code below, I'm just trying to confirm the behavior before I add the SQL update statement to the function. (I'm typically only retrieving or inserting data for a web site - very little experience updating the data between a single page like this.)
<br>
<form method="POST" id="form" action="">
<table>
<tr>
<td>
<select name="state">
<%
'populate the dropdown selection for the state within the form
do until rs.eof
For each x in rs.fields
response.write "<option value=" & x.Value & ">" & x.Value & "</option>" & vbNewLine
next
rs.movenext
loop
%>
</select>
</td>
<td>
<select name="ps">
<option value="blank"></option>
<option value="prime">Primary</option>
<option value="secondary">Secondary</option>
</select>
</td>
<td>
<input name="emp_num" size="5" maxlength="5" rows="1" ></textarea>
</td>
<td>
<input type="submit" onclick="Go" value="Update record"/>
</td>
</tr>
</table>
</form>
<%
function Go() {
msgbox "test"
//additional SQL code would be included here once the function actually works
}
%>
<%
'close the DB connection
dbconn.close
%>
</body>
</html>
You're trying to mix server-side code with client-side code, and It Don't Work Like ThatTM.
Here's a very rough outline of how you could get information from the user, process it, and display it, all on the same asp page. Note the utter lack of JavaScript. :)
<html>
<head>
<title>My Page</title>
<link rel="stylesheet" type="text/css" href="css/stylestuff.css">
<%
Dim rs, sql, conn
Dim mylist, myval1, myval2, i
myval1 = Request.Form("val1")
myval2 = Request.Form("val2")
'- If the form hasn't been submitted yet, myval1&2 will be the special value Empty,
'- but you can treat them as a blank string ("") for all intents and purposes.
If Validate(myval1, myval2) = True and myval1 & myval2 <> "" Then
DoStuffWith myval1, myval2
End If
%>
</head>
<body>
<h1>My Page</h1>
<form method="post" action="">
<p>Select one: <select name="val1" size="1">
<%
ListStuff mylist
For i = 0 to UBound(mylist,1)
response.write "<option value='" & mylist(0,i) & "'"
If myval & "" = mylist(0,i) & "" Then response.write " selected"
response.write ">" & mylist(1,i) & "</option>"
Next
%>
</select></p>
<p>Write something here:
<input type="text" name="val2" value="<%=myval2%>" size="10"></p>
<p><input type="submit" name="btn" value="Submit"></p>
</form>
<%
If myval1 & myval2 <> "" Then
DisplayStuff myval1, myval2
End If
%>
</body>
</html>
<%
Sub ListStuff(L)
sql = "Select [...] From [...] Where [...]"
Set rs = Server.Createobject("ADODB.Recordset")
rs.Open sql, "connection string (or previously-opened connection object)", 1,2
If Not rs.EOF Then
L = rs.GetRows
Else
Redim L(1,0)
L(0,0) = 0 : L(1,0) = "missing!"
End If
rs.Close
Set rs = Nothing
End Sub
'---------------------------------
Function Validate(v1,v2)
dim f
f = True
If Not Isnumeric(v1) Then f = False
If Len(v2) > 10 Then f = False
Validate = f
End Function
'---------------------------------
Sub DoStuffWith(v1,v2)
'- table-creation (or whatever) code goes here
End Sub
'---------------------------------
Sub DisplayStuff(v1,v2)
'- display code goes here
End Sub
%>

How to Provide Breadcrumbs for Page with dynamic Parameters?

I found a Grails framework for generating Breadcrumbs here. It does generate breadcrumbs based on a static definition in a breadcrumbs.xml file where it defines the hierarchies of the crumbs:
<map>
<nav id="homeCrumb" matchController="samplePages" matchAction="homeBreadCrumbPage">
<!-- levels navigation -->
<nav id="itemsLevel1Crumb" matchController="samplePages" matchAction="level1BreadCrumbPage">
<nav id="itemsLevel2Crumb" matchController="samplePages" matchAction="level2BreadCrumbPage">
<nav id="itemsLevel3Crumb" matchController="samplePages" matchAction="level3BreadCrumbPage">
<nav id="showItemCrumb" matchController="samplePages" matchAction="itemDetailsBreadCrumbPage"/>
</nav>
</nav>
</nav>
<nav id="simple1Crumb" matchController="samplePages" matchAction="simpleBreadCrumb"/>
<nav id="simple2Crumb" matchController="samplePages" matchAction="simpleBreadCrumbWithAttr"/>
<!-- levels navigation -->
</nav>
</map>
This file is evaluated and printed by a taglib:
class BreadCrumbTagLib {
static def log = LogFactory.getLog("grails.app.breadCrumbTag")
def breadCrumb = { attrs , body ->
def manager = BreadCrumbManager.getInstance()
def uri = request.getRequestURI()
def context = request.getContextPath()
def controller = params.controller
def action = params.action
def attrTitle = attrs.title
def attrLink = attrs.link
// if controller and action are missing from params try to get them from request url
if (!controller && !action && uri && context && uri.indexOf(context) != -1) {
def uriParams = uri.substring(uri.indexOf(context) + (context.length() + 1), uri.length())
def uriArray = uriParams.split('/')
if (uriArray.size() >= 2 ) {
controller = uriArray[0]
action = uriArray[1]
}
}
def crumbs = manager.getBreadCrumbs(controller, action)
if (crumbs) {
out << '<div class="breadcrumb"><ul>'
def size = crumbs.size()
crumbs.eachWithIndex { crumb, index ->
out << '<li>'
// override title and link of breadcrumb on current page (i.e. last bread crumb in hierarchy)
// if name, link attributes are supplied
if (index == size - 1) {
if (attrTitle)
crumb.title = attrTitle
if (attrLink)
crumb.link = attrLink
}
// set title to undefined if not found, associated
// renderer if present can overwrite it
if (!crumb.title)
crumb.title = "undefined"
if (crumb.title && crumb.title.size() > 40)
crumb.title = crumb.title.substring(0, 40) + "..."
if (crumb.viewController && crumb.viewAction) {
def content = g.include(controller:crumb.viewController, action:crumb.viewAction, breadcrumb:crumb, params:params)
out << content
} else if (crumb.viewTemplate) {
def content = g.include(view:crumb.viewTemplate, breadcrumb:crumb, params: params)
out << content
} else if (crumb.linkToController && crumb.linkToAction && (size - 1 > index)){
out << "${crumb.title}"
// if crumb has a link and its not the last vread crumb then show link else
// just show the text
} else if (crumb.link && (size - 1 > index)){
out << "${crumb.title}"
} else {
out << "${crumb.title}"
}
out << "</li>"
// do not print for last bread crumb
if (size - 1 > index)
out << "<li>ยป</li>"
}
out << "</ul></div>"
}
}
}
Problem: When I have a structure where I need some params which are not fix.
Example: I am in the third level of navigation lets say
A1 / A2 / A3
In my case A2 should open a page like user/show/1234 where 1234 is the id of the user to show. The problem is that I cannot add 1234 hard coded in the breadcrumbs.xml file because this id changes depending on which user you want to show.
How can I handle this when an intermediate breadcrumbs link needs dynamic parameters?
After thinking about it some more, I realized it may be better not to use the HttpSession. If you use a session-scoped service instead it will be easier to unit test the breadcrumb code.
First, create a session-scoped service to maintain the user's navigation history.
class NavigationHistoryService {
static transactional = false
static scope = "session"
def history = [:]
public List push(String controller, String action, Map params) {
def crumb = [
action: action,
params: params]
history.controller = crumb
return history
}
In your controllers inject the service and use it to keep track of where the user has been. Then add the history as part of what's returned by the action's model:
class CompanyController {
def navigationHistoryService
def show() {
navigationHistoryService.push('company', 'show', params)
...
[crumbs: navigationHistoryService.history]
}
}
Finally, use the history in your GSP to render the crumbs.
<ol class="breadcrumb">
<li><g:link controller="company" action="${crumbs.company.action}" params="${crumbs.company.params}">SOMETHING</a></li>
</ol>
It looks like your breadcrumbs are in the format CONTROLLER/ACTION/ID. If that's so, the information you need is already available in your GSP via the webRequest property. Here's an example using Twitter Bootstrap breadcrumbs:
<ol class="breadcrumb">
<li>${webRequest.controllerName}</li>
<li>${webRequest.actionName}</li>
<li class="active">${webRequest.id}</li>
</ol>
You'd still have to set up the hrefs to something meaningful. A more robust approach would be something like this...
<g:set var="crumbs" value="${[webRequest.controllerName, webRequest.actionName, webRequest.id].findAll { it != null }}.collect { [label: it, active: false] }" />
<% crumbs.last().active = true %>
<ol class="breadcrumb">
<g:each in="${crumbs}">
<li class="${it.active ? 'active' : ''}">${it.label}</li>
</g:each>
</ol>
Embedding Groovy code into GSP via the <% %> tags is not recommended, but something like this could be done in a TagLib. This approach can handle breadcrumbs of 1-3 parts in length. It adjusts according to the current URI.
use simple by blade view
<ul class="breadcrumb" style="padding-right: 20px">
<li> <i class="fa fa-home"></i> <a class="active" href="{{url('/')}}">Home</a>
{{--<i class="fa fa-angle-right"></i>--}}
</li> <?php $link = url('/') ; ?>
#for($i = 1; $i <= count(Request::segments()); $i++)
<li>
#if($i < count(Request::segments()) & $i > 0)
<?php $link .= "/" . Request::segment($i); ?>
<a class="active" href="<?= $link ?>">{{Request::segment($i)}}</a>
{{--{!!'<i class="fa fa-angle-right"></i>'!!}--}}
#else {{Request::segment($i)}}
#endif
</li>
#endfor
</ul>

Permission Denied when Using [objshell browseforfolder] in vbs on html page

I am trying to use [objshell browseforfolder] with vbs in HTML to make a folder browser. It is working fine in hta but when I put it into html page, it always show me that permission denied. I did some research on this, looks like IE does not support folder browse for security reason.....so my question is that is there anyway to make it work? I m using it on a internal page, so security wont be an issue.....
Here is the code:
<html>
<head>
<script language = "VBScript">
Sub ChooseSaveFolder_OnClick()
strStartDir = "c:\work"
userselections.txtFile.value = PickFolder(strStartDir)
End Sub
Function PickFolder(strStartDir)
Dim SA, F
Set SA = CreateObject("Shell.Application")
Set F = SA.BrowseForFolder(0, "Choose a folder", 0, strStartDir)
If (Not F Is Nothing) Then
PickFolder = F.Items.Item.path
End If
Set F = Nothing
Set SA = Nothing
End Function
</script>
</head>
<body>
<form name="userselections">
<input type = "text" name = "txtFile" size="50" />
<input type = "button" value = "Browse ..." Name="ChooseSaveFolder">
</form>
</body>
</html>

asp form question

I have this form
<form action="http://www.mysite.com/asp/formd.asp" method="post" target="_blank">
so the asp looks like below,
it opens a new window where ot says "send ok"
my question is how and where can I contro/define the style of this new window i.e background fonts color etc
thanks
the ASP code:
<%# Language=VBScript %>
<%
Dim txtbody
Dim objCDO
Set objCDO = Server.CreateObject("CDONTS.NewMail")
objCDO.To = "mail#mail.com"
objCDO.From = "digital#adinet.com"
objCDO.Subject = "* *Formu enviado desde web * *"
txtbody = ""
for a = 1 to Request.Form.Count
txtbody = txtbody & Request.Form.Key(a) & " = " & Request.Form(a) & chr(10) & chr(13)
next
for a = 1 to Request.QueryString.Count
txtbody = txtbody & Request.QueryString.Key(a) & " = " & Request.QueryString(a) & chr(10) & chr(13)
next
txtbody = txtbody & "*******-----------------******"
objCDO.Body = txtbody
objCDO.Send
Response.Write "send = Ok"
%>
If you'd like to have a page or message that's more meaningful, consider replacing this
Response.Write "send = Ok"
with this:
Response.Redirect "email-thank-you.htm" 'or .asp, whatever you like.
Then go make your new page email-thank-you.htm as decorated and styled as nicely as you can. This helps by having your email logic contained in one page or function, and separate from the nice page. If something happened, i.e. the email server was unavailable, or perhaps the email address was malformed/missing, you could write that back to the original page.
If I understand what you're doing correctly, you should actually create a static form called emailForm.asp with your desired styling. Have it read the querystring that you are passing and and place the values in the fields. Put on link on your current page in order to pop this page up.
Your final line, Response.Write "send = Ok" is being output as a badly-formed html page.
I'd recommend you structure your page as follows:
<%# Language=VBScript %>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<!-- Add header info, including links to style sheets -->
</head>
<body>
<%
'Your CDO code goes here
objCDO.Send
if err.number > 0 then
response.write "<p class='error'>Error: " & err.number & " - " & err.message & "</p>"
else
Response.write "<p class='ok'>Sent OK</p>"
end if
%>
</body>
</html>
This will render a full html page that you can style properly (and will also no presume that the email sent OK!).