I have a number of aspx pages contained in external assemblies which are loaded via a custoer PathProvider, all works fine with the exception of local resources for the pages.
So for example, I have a project Paul.Pages, within Paul.Pages there are a number of aspx pages, these are all embedded resources and are loaded view PaulPathProvider.
I have page welcome.aspx which has a single lable welcomeLable (and I have set the Text property to "Hello World") in Paul.Pages, I have generated local resources for this page and now in Paul.Pages I also have a App_LocalResources folder with welcome.aspx.resx, in the .resx file I have welcomeLabelResource1.Text = "Hello Paul".
When the page loads I would expect to see "Hello Paul" but actually it displays "Hello World" implying the resource string is not being loaded, I have tried setting the welcome.aspx.resx to Embdedded Resource but it makes not difference.
Any help is much appreciated, this is driving me nuts.
Addiontal Info
So the welcome.aspx is contained in an assembly OliveERP.Common and is named welcome.aspx, this has Build Action = Embedded Resource as it is loaded using a custom path provider. The OliveERP.Common has a App_LocalResources folder containing welcome.aspx.resx the page html is
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="welcome.aspx.cs" Inherits="OliveERP.Common.welcome" culture="auto" meta:resourcekey="PageResource1" uiculture="auto" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label runat="server" ID="welcomeLabel" Text="Hello World" meta:resourcekey="welcomeLabelResource1" />
</div>
</form>
</body>
</html>
but page still displays Hello World not Hello Paul
seems the following is your problem
in the .resx file I have welcomeLabel.Text = "Hello Paul".
<asp:Label runat="server" ID="welcomeLabel" Text="Hello World" meta:resourcekey="welcomeLabelResource1" />
When your label's resourcekey is welcomeLabelResource1 then in your resx file you should have a resource string welcomeLabelResource1.Text for the Text property.
May be you have your resource files as "Embedded Resources" Try making them "Content" files.
Related
Here is my project directory where I have
style.css
under Content and
image.jpg
under Images
Login.aspx page is default page.
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="LoginDemo.Login" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<link href="~/Content/style.css" rel="stylesheet" type="text/css" media="screen" runat="server" />
<title>LOGIN</title>
</head>
<body>
</body>
</html>
And here is CSS
*{
margin:0px;
padding:0px;
}
body{
background-image:url(Images/image.jpg);
background-size:cover;
background-attachment:fixed;
font-family:Times New Roman ;
}
Page is loaded successfully but without loading background image. Please help me. I read different article and as per suggested solutions I do the same steps but still there is problem.
Images is not in the Content folder. so in your css, you should go back a folder:
background-image:url(../Images/image.jpg);
Note the ../ before Images folder in the path
put a single quote before and after your image path,and also use (..) to refer up directory, so correct your css code with these lines:
*{
margin:0px;
padding:0px;
}
body{
background-image:url('../Images/image.jpg');
background-size:cover;
background-attachment:fixed;
font-family:Times New Roman ;
}
and where is your webpage location ? is it in a directory ?
Create an error in style.css file, compiler didn't listening the file. clean the solution and Rebuilt it again. Surely It will work.
i want to convert my html file to pdf in that process i took all html tags and elements into an asp textfield on button click its giving the above error
code is
code.aspx
<asp:TextBox ID="TxtHtmlCode" CausesValidation="false" runat="server" Width="90%" Text="" TextMode="MultiLine" Height="150px"></asp:TextBox>
<asp:Button ID="BtnCreatePdf" runat="server" Text="Create PDF" OnClick="BtnCreatePdf_Click" CssClass="mybutton" />
code.aspx.cs
protected void BtnCreatePdf_Click(object sender, EventArgs e)
{
htmlString = TxtHtmlCode.Text;
HtmlToPdf converter = new HtmlToPdf();
PdfDocument doc = converter.ConvertHtmlString(htmlString);
doc.Save(Response, false, "Sample.pdf");
doc.Close();
}
i check with breakpoints even its not going to button click function.
please help me..
You want to use HTML editor like opensource ckeditor.
It'll basically encode and decode html elements when you post the page back to server.
<%# Register Assembly="CKEditor.NET" Namespace="CKEditor.NET" TagPrefix="CKEditor" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<CKEditor:CKEditorControl ID="CKEditor1" BasePath="/ckeditor/" runat="server">
</CKEditor:CKEditorControl>
<asp:Button ID="BtnCreatePdf" runat="server" Text="Create PDF"
OnClick="BtnCreatePdf_Click" CssClass="mybutton" />
</form>
</body>
</html>
FYI: I personally do not like to use validateRequest="false"; it'll end up creating security hole.
Inside of your web.config you'll want to do:
<HttpRuntime requestValidationMode="2.0" />
Your other option, is to also append to your page directive at the top of your .aspx and apply:
<#Page ... validateRequest="false" %>
Keep in mind, by adding to web.config it will affect your entire site, compared to the page directive. However, by adding this to your application, you obviate some built in security that Microsoft utilizes in the Web-Forms Framework.
I followed some examples in my ASP.NET 4.5 in C# book for Master Pages. So I made a more complex site using them, and it all works locally. But when I push it to my remote server, it is saying the file cannot be found. So I made a more basic master page in Visual Studio 2015 to check. And it works locally, but when pushed to the remote server, it still does not work. I couldn't find any answers online either. I've tried some different urls thinking I was using the wrong url too. I've used
myWebSite.com/TestFolder/MasterPage.master
myWebSite.com/TestFolder/
myWebSite.com/TestFolder/MasterPage
So I'm not sure what I'm doing wrong. Any help would be greatly appreciated.
The code for my master page looks like this:
<%# Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Tester</title>
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<h1>This is a test of the master page.</h1>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
I fixed it. I made sure that the file path to the CodeFile in the header was "./MasterPage.master.cs" and the MasterPageFile reference in the header of the content page was "./MasterPage.master" not "~/MasterPage.master".
The url also worked just as myWebSite.com/
Thank you for the help anyways. Much appreciated.
Please take a look at this link :
http://forums.asp.net - Obfuscate aspx pages
I have the same problem and my problem is how can i obfuscate aspx pages with c# codes inside?
I know for .net dlls we can use :
Dotfuscator
Or
Other third party programs...
But what about aspx files with c# codes and my purpose is to obfuscate c# method names and strings in that file!
EDIT :
My aspx file is like this :
<%# Page Language="C#" Debug="true" trace="false" validateRequest="false" EnableViewStateMac="false" EnableViewState="true"%>
<%# import Namespace="System.IO"%>
....
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
C# Codes...
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title></title>
<style type="text/css">
...
</style>
<script type="text/javascript">
...
</script>
</head>
<body>
<form id="" runat="server">
...
</form>
</body>
</html>
obfuscation of aspx(html) part is not important for me and only want to obfuscate C# Codes...
Edit 2 :
What is your purpose?
Are you crazy?
No, i'm not.
sometimes i don't have access to Visual Studio and want to write a little project very quickly in a single file with c# codes and gave it to my customer.
Based on what you said, "how can i obfuscate such these files (aspx codes + c# codes in one file)?" You cannot do that. You can use the Code-Behind Model which is where you C# code in a separate file.
Code-Behind
Code-behind refers to code for your ASP.NET page that is contained
within a separate class file. This allows a clean separation of your
HTML from your presentation logic.
To manage the page title on my pages, I have a master page with a ContentPlaceHolder in the header.
<head runat="server">
<asp:ContentPlaceHolder runat="server" ID="headContent">
</asp:ContentPlaceHolder>
</head>
On each of my pages, I add the meta tags and page title as follow:
<asp:content id="Header" contentplaceholderid="headContent" runat="server">
<meta name="keywords" content="keyword1, keyword2" />
<meta name="description" content="page description" />
<%Page.Title = "My page title";%>
</asp:content>
I cannot modify the code on the pages by placing the Page.Title in the OnInit method of the page.
I need access to the page title in the codebehind of the master page, but I always get an empty title when I use Page.Title.
By using <%Page.Title = "My page title";%> you implicitly tell the ASP.NET to execute this embedded code block during the page's render phase.
What does it mean? You won't be able to get this value before the page's render phase. Assuming you're trying to get this value a little bit earlier than during the render. That's why you get the empty string.
The workaround could be in setting your Title property of the <%# Page directive in the beginning of your page e.g.:
<%# Page Title="My Title Goes Here" Language="C#" ... %>
By setting this you'll be able to access the Page.Title property from your master page a little bit earlier than the page's rendering occurs.
Just use
<title>My page title</title>