ASP.NET Controls Not Recognized - asp.net

I just installed the release version of Visual Studio 2010, and it looks like there's something wrong with the standard ASP.NET server controls.
When I create a basic server control, such as a TextBox, the editor underlines it in green and says (I also get no intellisense for ASP.NET controls):
Element 'TextBox' is not a known element. This can occur if there is a compilation
error in the Web site, or the Web.config file is missing.
The web site builds fine, and the Web.config file is not missing:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="false" targetFramework="4.0" />
</system.web>
</configuration>
The controls work just fine in the code-behind, and they function correctly when I run the site.
Is there some configuration problem here?

This person who's a tester on the Visual Web Developer Team offered this workaround, which apparently worked:
Close VS, delete schema cache, and re-open VS. You can find the schemas under something like:
C:\Users\Pavel\AppData\Roaming\Microsoft\VisualStudio\10.0\ReflectedSchemas
It is safe to delete all files in this folder.

I've encountered the same problem, but deleting the cache didn't solve it for me.
However based on the other answer, I modified the already set master page path in the .aspx file (MasterPageFile="~/MasterPage.master")
to something nonexistent, saved the file, then changed it back to the original path. After this the underlining was gone, and intellisense worked properly.
Funny that this is still a thing 2020. Using VS2019 Community.

Extension on the question as your solution didn't work for me.
I was seeing this in my SharePoint 2010 Application Pages which did not specify a masterpageurl in the Page tag.
Solution: After setting MasterPageURL="~masterurl/default.master" to the Page tag in the designer, it fixed all my ASP tags.

In my case, I noticed the MyPage.aspx.designer.cs was missing. Once i made a copy of existing file and defined the controls, all was set.
Please note for me, there were three files.
MyPage.aspx
MyPage.aspx.cs
MyPage.aspx.designer.cs
The definition of controls looks something like this:
protected global::System.Web.UI.HtmlControls.HtmlInputText txtName;
/// <summary>
/// txtAddress control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.HtmlControls.HtmlInputText txtAddress;

Related

Using Handler in DLL

If I open ASP.NET, create a blank site, add a handler file, add a webform then on the webform add an image control and set the imageurl to handler.ashx, all works fine.
Open Visual Studio 2013 or 2015, create a class library project, delete the vb file that's created, add an ASP.NET handler and use the same code as in the above handler.ashx file, compile the code and then add a reference to that DLL from the asp.net project which copies the DLL to the bin folder. My question is, how to use that handler in the asp.net project?
Sure, in the web.config you can add to the hadlers section (not httphandlers) but if registering *.zzz as the extension and then in the imageurl of the image control. ex: "aaaaaa.zzz" it should return a jpg file because of the code in that handler but nothing happens. What am I doing wrong?
I've created a test app to replicate your issue and all works fine for me.
Here is a snippet of my handler configuration, compare it to what you have got:
<system.webServer>
<handlers>
<add name="imageHandler" verb="*" path="*.zzz" type="CustomHandlers.ImageHandler, CustomHandlers"/>
</handlers>
</system.webServer>
if this didn't work, please send the details of the error/exception you are getting.
I am not sure if it is possible to trigger a handler through a dll. What worked for me was using my handler on my local project, and then having the handler call a method from the class library project. That method can then contain all of the logic that is meant to be in your handler.

No owin.Environment item was found in the context

Microsoft recently introduced new ASP.NET Identity - replacement for old (Simple)Membership. Unfortunately, I can't use this new membership system in my old project because it throws System.InvalidOperationException: No owin.Environment item was found in the context. This is a known bug, but Microsoft keeps silence about this issue. The easiest way to reproduce this bug - it's to create a new web application (MVC, WebForms or WebApi - doesn't matter) in VS 2013 (with Web Tools 2013 Preview Refresh) and then go to the login page. It will work. Then change namespace in your application to anything else than original namespace and login page will throw that error. Changing namespace back to original (the one you used at the creation of a project) will solve this problem.
It looks like .net stores somewhere something related to the original namespace, but I can't find what and where, it's not in the project folder. I know that stackoverflow is not a place for a bug reports, I just hoping that someone already found a solution for this issue or maybe people involved in the development of ASP.NET Identity will see this.
Most likely it cannot find the OWIN Startup class. The default convention for the Startup class is [AssemblyName].Startup. If you're no longer following that convention you'll need to specify the full name of your Startup class in the Web.Config.
The next release of Microsoft.Owin.Host.SystemWeb package now throws detailed exception messages when the Startup class cannot be found.
I had the same issue, it was fixed after making sure this line was in web.config:
<add key="owin:AutomaticAppStartup" value="true" />
I had the exact same error, but as it turned out I had another configuration problem in my web.config. My web.config was missing the attribute defaultLanguage="c#" in the compilation element under system.web.
In this case it will default to VB. So unless you have your Startup class written in VB you should change the default language to C#.
Not correct:
<compilation debug="true" optimizeCompilations="true" targetFramework="4.6.1">
This is correct (unless you use VB):
<compilation debug="true" defaultLanguage="c#" optimizeCompilations="true" targetFramework="4.6.1">
Cleaning ASP.NET temporary files helped me with this exact problem
I created two new projects called TesteMvc5.2 and TesteMvc5.0 and both of them didn't work at start
this is because the default namespace is different from the assembly name.
but after I put the line
<add key="owin:AppStartup" value="TesteMvc5._2.Startup, TesteMvc5.2" />
on the web.config it worked fine.
I tried everything mentioned on this page but nothing worked. Then I found out about a setting in IIS named owin:AutomaticAppStartup. You can find it in the Application Settings page of the IIS Manager for the Default Web Site. Check to see if that setting is true. If not set to true. This worked for me.
This is the website where I found the answer:
http://gotoanswer.stanford.edu/?q=Microsoft.Owin.Host.SystemWeb+and+still+getting+No+owin.Environment+item+was+found+in+the+context
If you happened to have copied the below config from MVC4, you should remove it from web.config
<add key="owin:AutomaticAppStartup" value="false" />
I had this same issue. I fixed it with the web.config.
However I had changed the assembly name and namespace and did not find the original assembly name anywhere anymore.
I then discovered that clean was not removing the original assembly from the bin.
Aftter deleting the bin litter, I was able to remove the web.config OWIN entry.
None of the above answers worked for me.
Turned out my project was missing the "Startup" class that contains the following:
using Microsoft.Owin;
using Owin;
[assembly: OwinStartupAttribute(typeof(NAMESPACE.Startup))]
namespace NAMESPACE
{
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
}
}
}
This file called "Startup.cs" is located on the root folder (~/) of your project.
My "Web.config" doesn't have any of this "Owin" configuration posted on the other replies.
Had same problem. Thanks for the shared solutions.
this..
<add key="owin.AppStartup" value="Namespace.Startup, Namespace"/>
<add key="owin:AutomaticAppStartup" value="false"/>
fixed for me
I have no idea why this works but it did!
My problem was in VS2013. In the WebConfig, debug was set to true and I got that error. When I set it to false it worked fine and then I reset to true and it continued to work OK!
At first when debug was true before changing to false, I put a break point in my StartUp code and it wasn't reached at all. After changing to false pressing save and then back to true the StartUp code was called and the program works like it should.
I experienced this error in an Optimizely (Episerver) solution where I had two feature branches using the same CMS database. In one feature branch I was working on a proof of concept using a visitor criterion. So I had created something like this:
public class SomeVisitorCriterionSettings : CriterionModelBase
{
public override ICriterionModel Copy()
{
return base.ShallowCopy();
}
}
[VisitorGroupCriterion(
Category = "Some category",
DisplayName = "My visitor criterion")]
public class SomeVisitorCriterion : CriterionBase<SomeVisitorCriterionSettings>
{
public override bool IsMatch(IPrincipal principal, HttpContextBase httpContext)
{
// match logic here..
}
}
And within Episerver -> CMS -> Visitor Groups I had created an instance of this visitor criterion. After switching to the other branch where this code did not exist, but the instance in the database did, the Owin exception was thrown.
Deleting the visitor criterion in the CMS resolved the issue, but I honestly have no idea why this sort of exception is thrown. I would love to know though..
I have tried all of the above suggestions, without success;
then reading the documentation at:
https://learn.microsoft.com/en-us/aspnet/aspnet/overview/owin-and-katana/owin-startup-class-detection
I understood that the error was in the call to the assembly in the Startup.cs file:
wrong code:
[assembly: OwinStartupAttribute(typeof([AssemblyName].Startup))]
right code:
[assembly: OwinStartup(typeof([AssemblyName].Startup))]
so, I fixed the error removing the word Attribute from OwinStartupAttribute
adding default language to compilation in web.config did it for me!

Allow Html Content to be posted

Recently i have faced an interview question.
You have finished an ASP.NET application using .NET framework 3.5.
You plan to submit text that contains HTML code to a page in the application.
You need to ensure that the HTML code can be submitted successfully without affecting other applications that run on the web server.
What would be your option?
Add the following in Web.Config
<system.web>
<pages validateRequest="false"/>
</system.web>
Add the following in Machine.Config
<system.web>
<pages validateRequest="false"/>
</system.web>
I guess the correct answer could be (1). Just wish to confirm the answer from SO experts. Please help me.
You can also decorate the single action method with
[ValidateInput(false)]
public ActionResult Index()
{
return View();
}
This will result in more security because you have the
control when request validation happens.
1) is correct. by putting the code in machine.config you will affect the whole machine as this are global settings.
You plan to submit text that contains HTML code to a page in the
application.
Since it's just "a page," it would be much better to disable validation checking for that page alone, rather than for the entire application (web.config), much less for all apps on that server (machine.config).
To do that, set ValidateRequest="false" on the #Page directive.
without affecting other applications that run on the web server
This is the key, web.config will only affect the one application. Wheras machine.config will affect all over applications running on the server.

VB webform in IronPython asp.net website

I tried to bring a previously done webform made in vb.net to an IronPython asp.net website with no luck. After seeing it didnt work, I tried to write the simplest codebehind vb.net webform to see if there was a problem with vb.net in an IronPython website and I got the following usual error
"be sure that the defined class in this file matchs with the one in the attribute inherits and that it extends the right base page (page or control)" (sorry if the translation isnt the most accurate I get that message in spanish)
but if I create a vb.net webform in the same website, with the sourcecode in the same file (with the vb.net code between script runat="server" tags in the same page) I get no problem.
Do I have to configure something for both kind of sourcecode languages to run in such way in the same IronPython website, like configuring something in the webconfig file or is there some compatibility issue for doing that which can't be resolved?
The code between <script /> tags is compiled dynamically when the page is first run. This enables you to mix languages. However, the classes in your code-behind files are statically compiled into an assembly by VS.NET ... and a VS.NET project can only support one language at a time.
One solution is to put your VB.NET code-behinds in a separate assembly. For example:
Add a new VB Class Library project to your existing solution
Add a reference to System.Web
Create your VB.NET code-behinds. They should be normal classes inheriting from System.Web.UI.Page.
In your ASP.NET website project, add a reference to the new project
Edit the # Page directives in your *.aspx files to inherit the classes in the new project
e.g. <%# Page Inherits="YourNewVBClassLibraryProject.MyVBCodeBehinds" ... /> where the Inherits attribute contains the relevant namespace-qualified class name
Thanks for the reply Serilla. Your information was interesting but I simply solved it by creating the app_folder and adding the vb files there. Do you think I could have some future problem for doing so?
The problem with the vb files was when these lines in the web.config were enabled for Ironpython to work
<pages compilationMode="Auto" pageParserFilterType="Microsoft.Web.Scripting.UI.NoCompileCodePageParserFilter" pageBaseType="Microsoft.Web.Scripting.UI.ScriptPage" userControlBaseType="Microsoft.Web.Scripting.UI.ScriptUserControl">
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</controls>
</pages>
when I removed them, vb code behind files worked but ironpython didnt. When the lines were there, Ironpython code behind files worked but vb ones didnt

Problem removing codeSubDirectories elements in sub-application

I have an ASP.NET application with a <codeSubDirectories> section in web.config. My main project is in VB.NET but I have a CSCode subdirectory under App_Code written in C#. Now for every new sub application I create I have to create a CSCode folder under App_Code. Microsoft's documentation says there is a <clear /> element but I get an error when I add it to the sub application's web.config file. What's going on?
Found it. Apparently Microsoft never got around the actually coding the <clear /> element for <codeSubDirectories>. The online MSDN Documentation mentions this in the Community Content section.
As a workaround I'm going to move the CSCode into a separate DLL.
If you didnt have the source code, you can create all subdirectories inside your App_Code subapplication, even with no content. Code works great, in the most cases.
References:
http://systemscenter.ru/avicodeenterprisedotnetmp2007manual.en/appendix-knowledgebase.htm

Resources