I am following Stephen Walther's guide and everything builds without errors. However once I run the application in Chrome I get this error message:
Application Cache Error event: Failed to parse manifest http://localhost/website/Manifest.ashx
And nothing is cached.
From what I have gathered from here, I have a type-o in my manifest. Maybe you can see something I did wrong and causing this error message.
Manifest.ashx:
<%# WebHandler Language="C#" Class="JavaScriptReference.Manifest" %>
using System;
using System.Web;
namespace JavaScriptReference {
public class Manifest : IHttpHandler {
public void ProcessRequest(HttpContext context) {
context.Response.ContentType = "text/cache-manifest";
context.Response.WriteFile(context.Server.MapPath("Manifest.txt"));
}
public bool IsReusable {
get {
return false;
}
}
}
}
Manifest.txt:
CACHE MANIFEST
CACHE:
Images/img1.jpg
Images/img2.jpg
JScript.js
Default.aspx.vb
# Does Default.aspx.vb even need to be cached?
TLDR: Don't add a CACHE: entry in your manifest, don't cache code-behind files and make sure you registered the HttpHandler in your Web.Config
Long Version:
There are a few things that you need to do to make the sample app work. First up you create your handler as above, an example in C# is:
using System.Web;
namespace CacheTest
{
public class Manifest : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/cache-manifest";
context.Response.WriteFile(context.Server.MapPath("Manifest.txt"));
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
Next you need to register the handler in your web.config like:
<configuration>
<system.web>
<httpHandlers>
<add verb="*" path="Manifest.ashx"
type="CacheTest.Manifest, CacheTest" />
</httpHandlers>
</system.web>
</configuration>
Next up create a Manifest.txt in the root of your website and populate it. The sample should not have a CACHE: heading inside it. A working sample may look like:
CACHE MANIFEST
# v30
Default.aspx
Images/leaping-gorilla-logo.png
Note that we do not cache code behind files, only relative paths to actual resources that a browser may request. Finally, add a Default.aspx file. Ignore the code behind but edit the markup so that the initial HTML tag references the HttpHandler, the full markup:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="CacheTest.Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" manifest="Manifest.ashx">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
This is a sample offline app!
</div>
</form>
</body>
</html>
With this done you can now start your website, browse to it in FireFox and you will be asked permission to take it offline. Alternatively, fire it up in Chrome, switch to the developer tools, check the Resources tab and you will be able to see the resources that have been loaded under the Application Cache node:
And for completeness, your finished code structure will look like:
The error "Application Cache Error event: Failed to parse manifest" can be caused by formatting of the text file.
My deployment script generated the manifest file in Unicode. The file looked fine in Chrome (when going to the URL), validated on online validators, but would generate this error when being used as a manifest.
To fix the file, just open the manifest file in notepad and go to "Save-As" and select UTF8.
Related
I have a content page that uses a MasterPageFile, and in the code we try to access a master property Master.SessionId.
<%# Page Title="" Language="C#" MasterPageFile="~/Admin/AdminFrontend.Master" AutoEventWireup="true"
CodeBehind="Reasons.aspx.cs" Inherits="Admin.Other.Reasons" %>
<asp:Content ID="Content2" ContentPlaceHolderID="cphMainBody" runat="server">
<reason session-id="<%=Master.SessionId%>">
</reason>
</asp:Content>
But the Master.SessionId is not recognized, Master is not referring to the correct master file. Similar code works on another file within the project. The only notable difference that we found is that the page that works has the following auto-generated code in the aspx.designer.cs file.
public partial class MyChart {
/// <summary>
/// Master property.
/// </summary>
/// <remarks>
/// Auto-generated property.
/// </remarks>
public new Admin.AdminFrontend Master {
get {
return ((Admin.AdminFrontend)(base.Master));
}
}
}
This is the designer for my Reasons.aspx file.
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Admin.Other
{
public partial class Reasons
{
}
}
I am not sure what is the problem, why in one file that property is auto-generated and not in the other. I thought Visual Studio is doing something crazy. I restarted VS2019 and also tried restarting my machine. Both didn't solve the
problem.
There may not even 'be' a Designer page for the "Reasons.aspx.cs". Please check to ensure it exists for the Reasons.aspx page (open the Solution Explorer and view the associated to the Reason.aspx file). If the Designer file does not exist, select/highlight the Reason.aspx file in the Solution Explorer, then use the upper menu bar (in Visual Studio), and choose the Project > Convert to Web Application selection. If that selection is missing from the Projects pulldown menu, this typically indicates all Designer files are connected to your CodeBehind files.
If you do have a Reasons.aspx.designer.cs, please provide the code here so we can compare it to the one from your MyChart example.
At your Reasons.aspx.cs file,
you can add public property and return the Master.sessionID.
For example;
public partial class MyChart
{
public string MySession
{
get
{
return Master.SessionID;
}
}
}
At your aspx file, use
<reason session-id="<%=MySession%>"></reason>
I am trying to implement forms authentication for our web application. All the code runs off a DLL written in delphi. I created an aspx file in my DLL to render the login form and I have successfully set up my IIS to redirect users to the aspx login page when they have not been authenticated.
Although the users are successfully redirected, the login form is not rendered on the browser.
Here is my FormsLogin.aspx code:
<%# Page language="c#" Codebehind="FormsLogin.pas" AutoEventWireup="false" Inherits="FormsLogin.TFormsLogin" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>
<form runat="server">
Password
<ASP:TextBox id="TextBox1" runat="server"/></form>
</body>
</html>
And here is the FormsLogin.pas code:
unit FormsLogin;
interface
uses
System.Collections, System.ComponentModel,
System.Data, System.Drawing, System.Web, System.Web.SessionState,
System.Web.UI, System.Web.UI.WebControls, System.Web.UI.HtmlControls;
type
TFormsLogin = class(System.Web.UI.Page)
{$REGION 'Designer Managed Code'}
strict private
procedure InitializeComponent;
{$ENDREGION}
strict private
procedure Page_Load(sender: System.Object; e: System.EventArgs);
strict protected
TextBox1: System.Web.UI.WebControls.TextBox;
procedure OnInit(e: EventArgs); override;
private
{ Private Declarations }
public
{ Public Declarations }
end;
implementation
{$REGION 'Designer Managed Code'}
/// <summary>
/// Required method for Designer support -- do not modify
/// the contents of this method with the code editor.
/// </summary>
procedure TFormsLogin.InitializeComponent;
begin
Include(Self.Load, Self.Page_Load);
end;
{$ENDREGION}
procedure TFormsLogin.Page_Load(sender: System.Object; e: System.EventArgs);
begin
// TODO: Put user code to initialize the page here
{ response.Write('<html><head><title>Test</title></head>'
+ '<body><form runat="server">'
+ 'Username '
+ '<input id="TextBox1" runat="server"/></form>'
+ '</body></html>'); }
end;
procedure TFormsLogin.OnInit(e: EventArgs);
begin
//
// Required for Designer support
//
InitializeComponent;
inherited OnInit(e);
end;
end.
If I add HTML code in the Page_Load procedure it does get renderred but I would very much like to avoid going down that path.
I have added the following verb in my web.cofig file:
<add name="FormLogin.aspx_*" path="FormsLogin.aspx" verb="*" type="FormsLogin.TFormsLogin, dll_name" resourceType="Unspecified" requireAccess="Execute" preCondition="integratedMode,runtimeVersionv2.0" />
I would appreciate any help you could give me.
Thanks.
I am getting this after
compiling,
made sure bin directory has the compiled DLL files.
What am I missing?
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: Could not load type 'WebApplication1.WebForm1'.
Source Error:
Line 1: <%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
Line 2: <!DOCTYPE html>
Line 3: Source File: /test/WebForm1.aspx Line: 1
check your namespace that is assigned to WebForm1. When I encounter this error it's typically due to me changing the namespace and not updating the line in .aspx file.
It may look like
namespace MyRenamedNamespace
{
public class WebForm1
{
}
}
in which case the line in the .aspx file should read
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="MyRenamedNamespace.WebForm1" %>
That means that the it cannot find the type/class of WebApplication1.WebForm1. I'd look in your code behind or WebForm1.aspx.cs and see if it looks something like:
namespace WebApplication1 {
public class WebForm1 {
protected void Page_Load(object sender, EventArgs e) {
}
}
}
I'd imagine your missing a namespace, or class name. If you can't find the code behind, I'd be tempted to recreate the page and Visual Studio should crate it for you.
I am trying to display an image from my database. I have an generic handler to display the image. But my problem is that it doesn't get called. My code for calling the handler is
Image1.ImageUrl = "~/ShowImage.ashx?id=" + id;
where id is a number and ShowImage.ashx is the handler. The breakpoints in .ashx file doesn't get hit either. I am new to asp.net. So any help would be highly appreciated.
In this cases the steps that you need to follow is to see how the html is rendered.
So, right click on the html page, and "view page source".
There locate the point that the ShowImage.ashx is called, and see if the full rendered path is correct.
From there you simple correct the path.
Additional you can use the browser tools to see what browser looks for, and if he finds it or not. On google chrome for example you make right click, then inspect elements and then click on the network. There you can see with red, what files your page can not find, and you need to fix the path.
Check this sample Example code this might help you.
ASPX Code :
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>
HTTP Handler class Impliment in Img tag
</h1>
<h1>Id : 1</h1>
<img src="ImageHandler.ashx?id=1" alt="Dynamic Image" />
<h1>Id : 2</h1>
<img src="ImageHandler.ashx?id=2" alt="Dynamic Image" />
</div>
</form>
</body>
</html>
C# Examples (ImageHandler.ashx File) :
<%# WebHandler Language="C#" Class="ImageHandler" %>
using System;
using System.Web;
public class ImageHandler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
//context.Response.ContentType = "text/plain";
//context.Response.Write("Hello World");
context.Response.ContentType = "image/jpeg";
if (context.Request.QueryString["id"] == "1")
{
context.Response.WriteFile("bamboo.jpg");
}
else
{
context.Response.WriteFile("palmtree.jpg");
}
}
public bool IsReusable {
get {
return false;
}
}
}
Here is live downloadable C# Examples and VB.Net Examples of this. Click Here...
Is there a quick and dirty way of using a query passed as follows:
domain.com/mypage.aspx/product/toycar/
I've done it before in PHP, but this needs to be done in page (in this instance).
--
I only have access to the aspx page and code behind, and have to work in asp.net 2 (i wish i was using 3.5)
quick and dirty:
public class ModuleRewriter : IHttpModule
{
public void Init(HttpApplication application)
{
application.BeginRequest += (new EventHandler(this.Application_BeginRequest));
}
private void Application_BeginRequest(Object source, EventArgs e)
{
// The url will look like: http://domain.com/mypage.aspx/product/toycar/
// The module will rewrite it to: http://domain.com/mypage.aspx?product=toycar
HttpApplication application = source as HttpApplication;
string[] urlInfo = application.Request.RawUrl.ToString().Split('/');
if (urlInfo.Length > 2)
{
string page = urlInfo[urlInfo.Length - 3];
string action = urlInfo[urlInfo.Length - 2];
string id = urlInfo[urlInfo.Length - 1];
if (string.IsNullOrEmpty(page))
{
page = "default.aspx";
}
application.Server.Transfer(string.Format(
"~/{0}?{1}={2}", page, action, id));
}
}
public void Dispose()
{
}
}
web.config:
<httpModules>
<add name="ModuleRewriter" type="ModuleRewriter, MyWebApplication"/>
</httpModules>
and a test page:
<%# Page Language="C#" %>
<!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>
<%= Request["product"] %>
</div>
</form>
</body>
</html>
You might want to look into the ASP.NET System.Web.Routing namespace, which was added in .NET 3.5 SP1 I believe:
http://blogs.msdn.com/mikeormond/archive/2008/05/14/using-asp-net-routing-independent-of-mvc.aspx
http://msdn.microsoft.com/en-us/library/system.web.routing.aspx
You'd be able to get rid of the .aspx extension too.
This would involve making a custom HTTP Handler.
Check this
You've got a few options, but all of them require access to the web.config and a change to IIS to map all file extensions to the dotNet ISAPI dll:
Use MVC (like stackoverflow does,
notice the urls)
Use asp.net routing (new in 3.5)
Write your own http handler Massive guide from Microsoft here
Use the excellent urlrewriting.net which does just about everything perfectly including getting round some awkward authentication and image path problems.
Personally I used urlrewriting.net with good results.
Since you mention you don't have access to anything but the code behind and the page, the only thing I can think of is actually creating those dirs (if you have access to do that) and using a server.transfer page passing the value to your actual page in the folder above. Messy, but if you can't access the other stuff, your choices are limited.
In case you just want to read the path from within your .aspx:
Request.ServerVariables["PATH_INFO"]
To clarify:
he has only access to the aspx (+ codebehind) itself, so he must know how the query is, but it is not in the Request.QueryString because of the format. So the only way then is Request.ServerVariables["PATH_INFO"] (Request.RawUrl)