asp.net dynamic data NEW custom page ERROR NOT FOUND - asp.net

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.

Related

Asp.net #Include external files in content

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");
}
}

cardIdentifier returned in URL QueryString rather than hidden-field

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.

Anti-Forgery token usage between MVC pages to classic ASP.NET pages

I have an application which has 80% of it's part in ASP.NET MVC 2.
I am using Anti-forgery token to avoid Cross-Site Request Forgery.
Say I have an action method -
public JsonResult AddMenuFavorite(int id) {
// code
}
which uses the token to prevent CSRF. I have various links in my MVC pages from there I can make a call to this action method smoothly without any error.
While making calls from classic ASP.NET pages, this shows error.
Reason:: Anti-forgery token is not embedded in ASP.NET pages it seems.
can any one help me with the solution?
In order to generate the required hidden field containing the token you could use the AntiForgery.GetHtml static method:
<%# Page Language="C#" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<%= AntiForgery.GetHtml() %>
<asp:LinkButton
runat="server"
ID="btn"
PostBackUrl="~/SomeController/AddMenuFavorite/123"
Text="Go to the MVC site"
/>
</div>
</form>
</body>
</html>
And since your action returns JSON I suspect that you are calling it using an AJAX request. In this case you can use the value of the hidden field generated by the helper to send it along with the AJAX request:
$(function() {
$('#someLink').click(function() {
$.post(this.href, $('form').serialize(), function(result) {
// do something with the result
});
return false;
});
});

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