HttpUtility is not recognized in my project - web-scraping

I try to write some basic CommandLine based HTML scraper
It is to be executed from a normal client 'dos' CMD console, so its not on a server.
I have set the project to .net 4.0 (not the default client 4.0 but the full one).
But still i am unable to make use of the word "HttpUtility" as in HttpUtility.UrlDecode(content);
On visual studio 2010
I am using
using System.Web;
using System.Linq;
using System.Text;
using HtmlAgilityPack;
using System;
using System.Collections.Generic;
using System.Net;
I have set a file reference to the htmlagilitypack, but HTTPutility is just plain .net 4.0 and not recognized
What do i do wrong ?

well i found the solution for it, make sure to add (manual) a reference to
System.Web
By default its not referenced in an console app, might be in an aspx app but not in an console like app. after adding it also as a reference it worked.

Related

I cannot reference .Net Standard 2 library in .Net Core 2 project

I have created a .Net Standard 2.0 class library and created some simple Dtos. Then I tried to reference it in .Net Core 2.0 web application and I could no do it. Visual Studio noticed that I should make a reference, but when I did that - nothing happened.
I'm using Visual Studio 15.5.1.
You missed a namespace import. Change ValuesController.cs
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
to
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using NetStandardLibrary;
Learn how to use Roslyn to fix such minor issues. That's an easier way out.
https://learn.microsoft.com/en-us/visualstudio/extensibility/getting-started-with-roslyn-analyzers
It turned out, that adding using was not enough. I needed to update Resharper from version 2017.1.1 to 2017.3.1. It is actually version 2017.2.1 that added a support for .Net Core 2.0: jetbrains.com/resharper/whatsnew/#v2017-2.
Try creating a .Net Core project with .Net Framework template.

Trying to get all the roles in asp.net application but getting error

I have this code
As you can see Roles is highlighted and that is what is causing the problem. The error says
'Microsoft.AspNet.Identity.RoleManager'
does not contain a definition for 'Roles' and no extension method
'Roles' accepting a first argument of type
'Microsoft.AspNet.Identity.RoleManager'
could be found (are you missing a using directive or an assembly
reference?)
It is saying are you missing reference or assembly? I am new to identity. I don't know what could be the problem. My header files seem to be fine
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using WebSite2;
The problem seems to that of identity-1 vs identity-2. The code I was running was for identity v2 but I was working with identity v1 (Visual Studio 2013) and hence the error. Switching to identity v1 fixes the problem. The correct code for v1 is
var context = new ApplicationDbContext();
var allRoles = context.Roles.ToList();
ListView1.DataSource = allRoles;
ListView1.DataBind();
which fixes the problem. Relevent question
Getting All Users and All Roles through asp.net Identity

cannot access MembershipUser in console app

I created a console app and converted it to .Net Framework 4.0 so that I could use System.Web.Security. I then added a reference to this class. I am able to access System.Web.Security.Membership but unable to access System.Web.Security.MembershipUser, it doesn't even show in intellisense as an option when I type System.Web.Security.
I seem to be missing a step but cannot figure out what step that is, any thoughts?
edit
using statements:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq;
using System.Text;
using System.Net.Mail;
using System.Web;
using System.Web.Management;
using System.Web.Security;
MembershipUser is in the System.Web.ApplicationServices assembly (dll), so you need to reference that in your project.

The language of the file referenced by the 'CodeFile' attribute does not match the language specified by the 'Language' attribute in the current file

When trying to edit a aspx page in Visual Studio i get the error:
The language of the file referenced by the 'CodeFile' attribute does not match the language specified by the 'Language' attribute in the current file.
What's the problem?
DocumentSearch.aspx:
<%# Page Language="C#" MasterPageFile="~/MasterPage.master"
AutoEventWireup="true"
CodeFile="DocumentSearch.aspx.cs"
Inherits="DocumentSearch"
Title="#Pepsi" %>
...
C# looks like it matches .cs to me.
DocumentSearch.aspx.cs:
using System;
using System.Data;
using System.Data.Common;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class DocumentSearch : System.Web.UI.Page
{
...
What's the problem?
i found the problem. It's that The Visual Studio language support for C# has not been installed.
The error message i was getting was misleading. The problem was that Visual Studio did not have C# installed - not that there was any mismatch. The reason C# was not installed is because i ran the wrong version of Visual Studio.
From the start menu i ran:
Microsoft Visual Studio 2008
when i should have ran
Microsoft Visual Studio 2008
The problem, of course, is that the former isn't really Visual Studio. It's actually:
Microsoft Visual Studio 2008 Shell (integrated mode)
Which is why C# wasn't available.

Visual Studio ASP.Net expand and collapse issue in ashx generic handlers

I have Visual Studio 2008 Professional and I am having issues with expanding and collapsing method code blocks in ASP.Net Generic Handler pages (.ashx)
I would have thought you could do the same thing like in the code behind of .aspx web pages.
I have this same issue on other boxes even with VS 2008 Standard and VS 2005 Professional. All boxes have been fully patched (OS and Visual Studio.)
Does anybody have any suggestions as to enabling this feature?
You can force Visual Studio to ignore the fact that it's code in front you're working with by going to:
Tools | Options
And opening the "Text Editor | File Extensions" tab.
Create a new entry for extension "ashx", mapped to editor "Microsoft Visual C#" (or "Microsoft Visual Basic", as your preference takes you), and "Add" it.
OK the dialog, close and re-open your ashx file, and your code blocks willl collapse to your hearts content, but the # directive will be rather ugly.
You have the same issue if you have serverside script in the .aspx file (for example in a web site project and you don't "Place code in a seperate file"), then you cannot collapse the class blocks in there either.
Create a class in the App_Code directory, which the ashx-file just references... like this:
SomethingHandler.ashx:
<%# WebHandler Language="C#" Class="SomethingHandler" %>
And in the App_Code folder I've created the file SomethingHandler.cs with class SomethingHandler
using System;
using System.Web;
// using blabla...
public class SomethingHandler : IHttpHandler
{
public void ProcessRequest(HttpContext c)
{
etc...
Now I can just open SomethingHandler.cs, edit my C# code with #region collapsing, because the .cs file is opened in the right editor :)
# WebHandler docs
Tested in VS 2019.
Just select a fragment of code, like:
using System;
using System.Web;
using System.Web.Security;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
Then Press "Ctrl+M+H" and Vualá... The Outlining Working Now... And Intellisense Too...
To Stop Outlining Press "Ctrl+M+P"...
Add /// in front of first line.
Like this:
///<%# WebHandler Language="C#" Class="FooBar"%>

Resources