Obfuscate aspx pages - c# codes are inside aspx files - c#

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.

Related

Page is loading without rendering style.css

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.

What do I have to do to get my ASP.NET MasterPage to work on my server?

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.

Display simple c# in "sharepoint online"

I am using "SharePoint Online" and I'm new to it. I have descend programming background and I need more Info on customisation of this service. I've never worked with .NET before (WHAT?!), but I would really like to learn more about C# and it's use in the industry. I have full access to SharePoint Designer and I have Visual Studio 2008.
1) How can I implement simple c# code on SharePoint web page?
2) How to import and use c# classes on SharePoint page?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<%# Page Language="C#" %>
<%# Register tagprefix="SharePoint" namespace="Microsoft.SharePoint.WebControls" assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta name="WebPartPageExpansion" content="full" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled 4</title>
<meta http-equiv="X-UA-Compatible" content="IE=10" />
<SharePoint:CssRegistration Name="default" runat="server"/>
</head>
<body>
<form id="form1" runat="server">
</form>
</body>
</html>
This is a brand new, empty .ASPX page generated by "SharePoint Designer". How can I import and display simple "Hello World", c# code on it?
Thank you very much in advance
Inside your <form> tag, insert this line:
<form id="form1" runat="server">
<% Response.Write("Hello World"); %>
</form>
Have fun learning C#
You cannot run server-side scripts on your ASP.NET pages in SharePoint online. It is not allowed and will tell you as much when you try to do this.
If you had an on-premises site, you could modify a setting in web.config to enable this, but that is beside the point.

Loading complete Html-page in contentpane of aspx-page

here at home I have different projects and libraries for which I've created an helpfile with Sandcastle.
Now Sandcastle provides also the possibility to create a website.
What I would like to do is to create an aspx-page where I can dynamically create a menu and where the existing helpfile-websites can be sollicited. All in one place.
Is it possible to accomplish this? Maybe some control that I can use to view an entire webpage?
Thank you.
EDIT:
Seems I can't get it to work in an ASP-page for whatever reason, but probably because of the way Sandcastle creates the help-pages.
I've now tried it with a WinForm-application with a webbrowser-control and this approach works, so I guess this will be the way I have to go here.
But I do need to say thanks to Alison (and Leon) for their help regarding this issue.
Their solution works for "normal" html-pages, but (unfortunately) not for the ones I have.
For that reason, I've accepted the answer so others could benefit from it.
Updated
Take a look at jQuery load. You can have a div on your page and load the html from an external page into it. The load function can grab individual pieces of HTML from a different page.
On your main page, add this html:
<div id="myexternalpage"></div>
On the different page, add a div tag with an id around the content you want to grab like:
<div id="myexternalcontent">Test</div>
The add the following to your head tag:
<script type="text/javascript">
$(document).ready(function() {
$('#myexternalpage').load('myexternalpage.html #content');
})
</script>
Notice the addition of the "#content" selector to the end of the load function? This will have jQuery load the different page and return only the content in the div with id="content".
Using jQuery load will let you load the content once the page loads and you won't need to use any iFrames. You can use CSS to handle the height/width and handle any overflow.
I've made a quick and dirty test-page:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Test2.aspx.cs" Inherits="Test2" %>
<!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">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js " ></script>
<script type="text/javascript">
$(document).ready(function () { $('#myexternalpage').load('WebHelp/KoenHoefman/ExhangeRateWebService/Index.html'); })
</script>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div id="myexternalpage">
</div>
</form>
</body>
</html>
But I get an error on the script line.
Microsoft JScript runtime error: Object expected
Do I have to replace document with something (probably a stupid question but I'm not used to use javascript)?
Update:
Added Leon's code and now it shows something. But when I want to use the page I really want to show (which is located in a subfolder) I get only the items on the index.html. The page that should be loaded into the IFrame of that page isn't shown. Also the pictures that are located in the same folder are not shown.
Error: HTTP 404
Requested URL:
/html/aea04102-3d0d-cf0d-f5f4-5634f5f06aed.htm

Different HTML, Same Codebehind & Same Controls

I am building a website which allows people to send out emails to people with a choice of different templates. When they have set-up their email and chosen a template the user can preview it. At present this loads up the corresponding aspx page to the template selected.
I currently have 3 templates but expect this to grow substantially.
The aspx pages all have the same controls, with the same names and even the codebehind(cs) page is the same. So it would be far simpler and efficient if i could somehow tie this pages together and minimise repetition, perhaps even just using one page but loading up the HTML corresponding to the selected template.
I cant think of an appropriate way to do this, or even work out if its possible. Ive probably got to the point where i cant think straight on the matter since its giving me such a headache.
So.....
Please please please give me some solutions or even just suggestions. ;-)
Thanks.
ADDITIONAL INFO
As an additional problem, i have to recreate the templates programatically when the emails are created and sent out to recipients as HTML emails. This is done via a different page and thus results in more duplication that id like to minimise.
create a Page class, let say, TemplateViewerPage
TemplateViewerPage.cs
using System;
using System.Web.UI;
public partial class TemplateViewerPage : Page
{
protected override void OnLoad(EventArgs e)
{
// load your properties
_subject = "test";
_messageBody = "body";
base.OnLoad(e);
}
// your property
private string _subject;
public string Subject
{
get { return _subject; }
set { _subject = value; }
}
private string _messageBody;
public string MessageBody
{
get { return _messageBody; }
set { _messageBody = value; }
}
}
then you can create viewer for template A :
ViewerA.aspx
<%# Page Language="C#" AutoEventWireup="false" Inherits="TemplateViewerPage" CodeFile="TemplateViewerPage.cs" %>
<!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>
<table>
<tr>
<td>Subject</td>
<td> <%= Subject %> </td>
</tr>
<tr>
<td>Message</td>
<td> <%= MessageBody %> </td>
</tr>
</table>
</div>
</form>
</body>
</html>
and ViewerB, with same code behind (codefile=TemplateViewerPage.cs)
ViewerB.aspx:
<%# Page Language="C#" AutoEventWireup="false" Inherits="TemplateViewerPage" CodeFile="TemplateViewerPage.cs" %>
<!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>
<div class="subject">
<%= Subject %>
</div>
<div class="message">
<%= MessageBody %> </td>
</div>
</div>
</form>
</body>
</html>
How about MasterPages for the templates? The select the appropriate master page at PageLoad.
If it's content then using CSS for the formatting (you can obviously change the CSS being loaded at Pageload) also Placeholders and populating them from your data store for the mails is another option.
It think there are probably as many solutions as there are users on StackOverflow ;)
If all the controls and code behind are the same, couldn't you put all the controls into a masterpage and simply use content pages for the actual emails?
Ah I see. Although it changes is it always in a similar structure? Because you can have multiple content holders in a masterpage. So in the masterpage you would be able to have content wrapped around the controls as follows:
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
<asp:Button ID="button1" runat="server" />
<asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server">
</asp:ContentPlaceHolder>
I haven't found that the asp.net web forms page, master pages, or mvc is a very good fit for this sort of thing. It's like using a sledgehammer to crack open a peanut.
It's very straightforward to create some custom xml tags and then merge them yourself. Save the template in the database and merge whenever you like, and without all the overhead of running asp.net. Use agile principles: create your tests first and work backwards and you'll have exactly what you need running in no time.
The most basic is straight string replacement. If you need more, which it doesn't sound like you do, you could use xslt or just walk the DOM (ie store your templates as xhtml and have your own custom tag support).
There's also an issue of deployment. It's a lot easier to update templates in a database than it is to upload files to a server. If you do go down the route of using web forms, make sure you understand the deployment scenario's before you .
Warning: html emails are tricky, and there's a lot of ugliness (from an html standpoint) to get them to render uniformly in email clients. Expect to code the html like it's 1999, and that's pretty much the state of html emails. Sad but true.

Categories