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"%>
Related
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.
I need to use excel automation in my ASP.NET web app. I am trying to import it in a .aspx file using the following code:
<%# Import Namespace="Microsoft.Office.Interop.Excel" %> however, when I open the page in the browser I get the error The type or namespace name 'Office' does not exist in the namespace 'Microsoft'. So I assume I have to add some library to my project. I am using IIS 7.5 to create this web app, not Visual Studio. So is there a way to import external libraries into my ASP.NET project in IIS?
Right click on the Reference - .Net tab - Microsoft.Office.Interop.Excel
Excel 2010 use version 14 / Excel 2007 use version 12
click ok.
You should be able to drop the Microsoft.Office.Interop.Excel.dll into the bin directory. If that doesn't work try adding it to the <assemblies> in your web.config file.
Assemblies in Web.config
Before anyone closes this as duplicate - please note its not a linq or other datasources issue and i have looked at other stackoverflow posts and none are same.
Here is my problem:
Its extremely simple app ASP.net with C# code behind no fancy stuff plain simple as you can see from code below:
default.aspx code
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%=returVar%>
Default.apsx.cs
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
public string returVar;
protected void Page_Load(object sender, EventArgs e)
{
string n = String.Format("{0}", Request.Form["test"]);
//below we will place the code for ODP.net once the DB connectivity is resolved
if (n.Length == 16)
{
returVar = "Found";
}
else
{
returVar = "Not found";
}
}//Page_Load
}
and finally web.config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="false"/>
</system.web>
</configuration>
My dev machine is: win 32 xp visual studio 2010 and Server running is Win 64bit 2008 R2 and IIS7.5.
so why is this error occuring when i run this code on my desktop it works like a charm with http through firefox as below:
http://localhost:3117/Default.aspx?test=0998989765432345
exact same code fails with attached screen shot, can someone tell me why please propose the solution. I tried including ALL of my DLL from solution explorer to release i.e. Solution Explorer > References > system.core, system.data etc... > all set for copy local = true.
still no luck.
Please note i cant install any extra components on the server and what ever i have to deploy has to be part of application.
Easiest solution if anyone else bumps into this situation, here is how i achieved result
open Visual studio 2010 once its loaded
open explorer -> goto > C:\Program Files\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0
copy the required System.ComponentModel.DataAnnotations.dll into your project "References" folder select that reference and under properties set "copy local" to true and once you publish it will be in your bin folder and wont impact at all on any server be it x32 or x64.
hope it helps anyone else.
Did you only install the client profile version of .NET 4.0 perhaps? You probably need the full version.
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.
Is it possible to version a asp.net site like doing so with AssemblyInfo.cs in Class Libraries?
According to the comments in the AssemblyInfo.cs in my ASP.net projects, you can:
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
I tried it, and yes, it works.
[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyFileVersion("1.0.*")]
On the AssemblyFileVersion I get a warning while building.
Yes. In VS:
right click web project,
go to properties
then application.
Click assembly information button - there you have the version fields.