C# - Clean User HTML In .net?
Jan 6, 2010
My C# site allows users to submit HTML to be displayed on the site. I would like to limit the tags and attributes allowed for the HTML, but am unable to figure out how to do this in .net.
I've tried using Html Agility Pack, but I don't see how to modify the HTML, I can see how to go through the HTML and find certain data, but actually generating an output file is baffling me.
Does anyone have a good example for cleaning up HTML in .net? The agility pack might be the answer, but the documentation is lacking.
View 6 Replies
Similar Messages:
Mar 21, 2011
I am attempting to replace this god awful collection of regular expressions that is currently used to clean up blocks of poorly formed HTML and stumbled upon the HTML Agility Pack for C#. It looks very powerful but yet, I couldn't find an example of how I want to use the pack which, in my mind, would be a desired functionality included in it. I am sure I am an idiot and cannot find a suitable method in the documentation. I had the following html:
<p class="someclass">
<font size="3">
<font face="Times New Roman">[code]....
When I utilize the HtmlNode.Remove() method it removes the node plus all it's children. Is there a way to remove the node preserving the children?
View 2 Replies
Mar 11, 2010
I would like to add html attributes to form inputs, specifically disabled="disabled" in addition to others. I have conditional logic in the Controller that determines whether to add this html attribute or not that sets a bool IsDisabled flag in my ViewModel e.g.
class ViewModel
{
bool IsDisabled {get;set;}
}
So in my View, I want to do something like:
<%= Html.TextBoxFor(x => x.Data, new {maxlength = 30, IsDisabled ? disabled = "disabled": null}) %>
or rather something like
<%= Html.TextBoxFor(x => x.Data, new Dictionary<string, object>().Add("maxlength", "30").AddConditional("disabled", "disabled", IsDisabled) %>
Except that Add returns void, and there is no such thing as AddConditional. Is there something like an MVC HtmlAttributeBuilder class, or should I just extend Dictionary with these two extension methods?
View 4 Replies
Oct 12, 2010
I am trying to use jQuery .load() to get straight html from a asmx web service:
$('#target').load('MyService.asmx/GetHtml');
In .NET code, GetHtml() returns as string:
[WebMethod(EnableSession = false)]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Xml)]
public string GetHtml()
{
return "<span>Hi</span>";
}
That returns:
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/"><span>Hi</span></string>
Notice that the string is encoded. With that encoding, $.load doesn't work right. The displayed text actually has the tags shown.
How can I get the WebMethod call to return just this?
<span>Hi</span>
View 4 Replies
Jun 10, 2010
I got a column which contains html content. The problem is, the content is not properly formatted. Meaning they consist of a big bulk of text, but without <p> or line break or proper <li>. Can anyone think of a quick way to write a script to tidy it up? I can't go through each and edit as there are like five thousands rows of them...
View 1 Replies
Aug 24, 2010
I'm considering to host WCF Rest Service that i've built on IIS 7. The URL to access my service will be something like
[URL]
Recently, i've been looking to some REST API implementation with a clean URL like Yahoo API
[URL]
I'm wondering what will be the best WCF host environment (e.g. Windows Service) or any solution (e.g. URL rewrite module) considering that I dont want to have application name and .svc in my URL so that I can have a completely clean URL for my REST API
View 2 Replies
Jan 19, 2010
I'm using asp.net/C# and I'm looking to create unique(?) uris for a small CMS system I am creating.
I am generating the uri segment from my articles title, so for example if the title is "My amazing article" the uri would be www.website.com/news/my-amazing-article
There are two parts to this. Firstly, which characters do you think I need to strip out? I am replacing spaces with "-" and I think I should strip out the "/" character too. Can you think of any more that might cause problems? "?" perhaps? Should I remove all non-alpha characters?
Second question, above I mentioned the uris MAY need to be unique. I was going to check the uri list before adding to ensure uniqueness, however I see stack overflow uses a number plus a uri. This I assume allows titles to be duplicated?
View 3 Replies
May 9, 2010
I am wondering having clear web.config file could be good but you know some shared web hosting companies don't allow us to touch things like machine.config and etc.
So If a lot of things have been moved onto machine.config, then will we be allowed to change things like we used to through web.config file.
View 1 Replies
Aug 11, 2010
There is an image for the surface, and a text is written on the image for 184 rows of date..
Thus, it is expected to see 184 different text written image files are generated with all the same background images. (The code is declared below...)
The problem is that the first text is written for all 184 different data.. I think I have to remove something in the loop. But what is that ??
[Code]....
View 1 Replies
May 21, 2010
Is there a better way to write the code below? I have quite a few blocks that are similar, and this is making the code in the Viewpage very messy to work with. The data value with the associated label only needs to be output when certain conditions are met, which is almost always if the value is not null. The options I can think is to use a response.write to atleast minimize the usage of the ASP script tags, or to format the webpage is such a way that the label displays with an appropriate n/a type value.
<% if (myData.Balance != null)
{ %>
Balance: <%= String.Format("{0:C}", (myData.Balance))%>
<% } %>
View 2 Replies
Dec 9, 2010
I once asked for a way to let a linkbutton pass more than one value in the commandArgument and then I reached the approach where I pass a string of multiple values separated by any character and split it into it's original parts...that didn't work out I don't know what was wrong with the splitting!
Now I tried the only solution I got, which is created a user control of the LinkButton and add properties to accept any values nedeed!...could you please tell me what's wrong with my 2 approaches and which is better ?
The first question can be found here : link text
and this is the code for the user control approach >>
MultivaluedLinkButton.ascx :
<asp:LinkButton ID="LnkBtnSort" runat="server" Text="Sort" OnClick="LnkBtnSort_Clicked"/>
MultivaluedLinkButton.ascx.cs :
public partial class MultivaluedLinkButton : System.Web.UI.UserControl
{
public event EventHandler Click;
private int _sortingType;
private string _sortingFactor;
private string _text;
public int SortingType
{
set { _sortingType = value; }
get { return _sortingType; }
}
public string SortingFactor
{
set { _sortingFactor = value; }
get { return _sortingFactor.ToString(); }
}
//public string Text
//{
// set { _text = value; }
// get { return _text.ToString(); }
//}
protected void LnkBtnSort_Clicked(object sender, EventArgs e)
{
if( Click != null )
{
this.Click(this, EventArgs.Empty);
}
}
}
Finally, Here's the implementation of my control inside an aspx page:
protected void MultivaluedLinkButton1_Clicked(object sender, EventArgs e)
{
MultivaluedLinkButton ctrl = (MultivaluedLinkButton)sender;
using (SqlConnection cn1 = new SqlConnection(ConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString))
{
using (SqlCommand cm1 = new SqlCommand(commandString2, cn1))
{
cm1.Parameters.Add("@arrange_by_id", System.Data.SqlDbType.Int);
cm1.Parameters["@arrange_by_id"].Value = ctrl.SortingType;
cn1.Open();
using (SqlDataReader dr1 = cm1.ExecuteReader())
{
SortBy_rpt.DataSource = dr1;
SortBy_rpt.DataBind();
}
}
}
}
The item template of the repeater in the implementation page :
<ItemTemplate>
<uc1:MultivaluedLinkButton ID="MultivaluedLinkButton1" runat="server" OnClick="MultivaluedLinkButton1_Clicked" SortingType='<%#Eval("arrange_by_id")%>' />
</ItemTemplate>
View 1 Replies
Oct 11, 2010
I haven't been able to find a post about this, but the HTMLEditor is finally a rich text editor that properly removes word formatting without messaging up other stuff (thank god!). However, because I know my users, I would like for this 'paste as word' mode to be always on whenever they paste, how can I accomplish this?
View 2 Replies
Feb 18, 2010
I am completely new to ASP.NET programming, and was asked to work on a small project involving ASP.NET, VB (which I am new to as well) and Microsoft SQL Server 2005.
Being used to php/java I was hoping to find some kind of similar API to php.net and the javadoc. It would be very useful to have as I would prefer to work with a text editor, instead of using DreamWeaver or Visual Web Developer.
In the project I basically only need to use ASP.NET to read from a SQL 2005 database and write to JSON files.
View 4 Replies
Apr 26, 2010
how can we clean text boxs after do request ajax.
i have 15 text boxs on my view.
View 3 Replies
Jan 22, 2010
Is there a way to clean all tables or objects within a database and make it like a brand new database?
View 3 Replies
Apr 14, 2010
can't find the Clean project under VWD2010, however, my project still works fine using the Build only, is this an upgrade?
View 2 Replies
Nov 4, 2010
I've just completed my first iPhone-compatible & Droid-compatible mobile app. At one time, I was confounded by differences in back button behaviour between the two platforms, but I came up with a suitable workaround.One thing remains that I'd like to correct if it's at all possible. The application is very session-variable dependent, so naturally, its very dependent on sessions. Users invariably use leave pages open when they turn off their smartphones, and this means that they return to a non-repsonsive timed-out page when they turn it back on. Can anything be done to preclude this? As in active web app or no web app?
View 7 Replies
Feb 19, 2010
How can i clean all the textbox's content in a single page?
without doing this textbox1.text = "";
View 4 Replies
Jun 2, 2010
In order to generate clean markup, I often resort to using code similar to this:
<asp:Literal ID="ltItem" runat="server">
<li class="{0}"><a href="{1}">{2}</a></li></asp:Literal>
And in the codebehind:
[code]....
Therefore my question:
Is this a common way to generate clean markup? Are there better alternatives? Is the databinding syntax approach preferable?
View 1 Replies
Mar 24, 2011
I'm using ASP.NET 4 and the routing engine. In my Global.asax I have something like this.
routes.MapPageRoute(
"Items",
"manager/items",
"~/Manager/Item/Items.aspx"
);
Is writing a link this this acceptable?: <a href="/Manager/Items"></a> Should I be using the <% %> tags and code within to retrieve the route name, "Items" in this case?
View 1 Replies
Mar 23, 2010
I work on an asp.net web application (3.5) with Visual Studio 2008. There are a lot of files in this project (approximately 500 aspx files) and I think I can remove some of them.
My question is: Is there a way to identify the useless files, I mean, the files that are no longer used in the project (like an image, aspx, etc.); by using Visual Studio or an external tool?
View 2 Replies
Mar 24, 2011
I'm working on a page that has a significant number of textboxes/dropdowns/etc to fill out. The majority of these are going to be performing some sort of custom validation. I should note that it's nothing of substantial size - all just string or integer values.
I always hear (and have typically always agreed) that as much validation should be performed on the client rather than on the server, but in this case I am unsure. The difference here is that this project will be passed on to an IT guy who knows about computers but is still new to programming - he will be the one in charge of making the minor updates and changes to the way these custom validations work in the future.
My idea shifted from being as efficient as possible to being a bit less efficient but much more readable. I created a new class specifically for all of my validations which will be used throughout the website. By forcing all of my custom validation code in this class, though, I eliminate any client-side validations I might be able to perform. I should also note that each page that requires a custom validation will generally need to perform at least one server-side validation, so I will never be able to use client-side 100%
Considering the relatively low level of activity on the website (currently and in the future), would you consider this as an acceptable solution? Or would you ALWAYS prefer to have as much validation on the client as possible in order to increase the responsiveness, even if it makes things a bit more messy for whoever may be working on it in the future?
View 2 Replies
Oct 9, 2010
I have installed SQL Server 2008 express, reinstall it with advanced services, uninstall TFS 2010 and tries to reinstall it but fails. It doesn't want to completely uninstall.
So I'd like to clean everything by hand (deleting registries, folders) but can't find any info. I have deleted install directory but installer still memorized that TFS is installed.
View 2 Replies
Jul 2, 2010
I have a data driven site that displays a lot of information, particularly images, using listviews contained within UpdatePanels, since this data can change with each post back you often see 'submit query' before the Item image appears. So, is there a way of making the page display only after it has finished loading data? The delay as the page loads is only brief but looks quite ugly when 'Submit query' appears all over the site.
View 2 Replies
Jun 24, 2010
I am trying to display an error to the user of a web page using a javascript alert popup, I currently have the following code to clean the error string:
errorMessage.Replace("'", "'")
But this is not sufficient as some illegal characters are not being removed, is there a static method somewhere in the framework that will format my string for clean insertion into html?Update: my initial question was slightly ambiguous. the string needs to be valid as in alert('this is some 'illegal text' that will not popup');I will try Server.HtmlEncode, hopefully it will do the trick.
View 7 Replies