Template ASP.NET MVC2 Web Application - asp.net-mvc-2

I’m new to MVC and am trying to set-up a basic template application. From VS2010 I’m creating the template MVC2 project. However, I’ve noticed that the database is sometime not created as part of the template. Are there any rules to when or where this creates its own database, or why it might not do so?

The standard MVC template has a connectionstring in the web.config pointing to a aspnetdb.mdf database in the App_Data folder.
The default MVC 2 Web Application template uses the database for authentication (through the AccountController).
The physical file gets created on first use; probably when you register an account or attempt a logon while running the application.

Related

Adding an AuthorizationHandler via config

In WCF, you can add an authorization policy through the web.config by using the serviceAuthorization node in a service behavior. Is there a way to include an AuthorizationHandler in .NET Core WebAPI via config?
To be clear, I'm trying to replace this line in Startup.cs with something in the web.config:
services.AddSingleton<IAuthorizationHandler, MyAuthorizationHandler>();
web.config is only used for IIS specific config. Because of .net-core's cross platform nature they ditched coupling to web config for application configuration.
A web.config file is required when hosting the app in IIS or IIS Express. Settings in web.config enable the ASP.NET Core Module to launch the app and configure other IIS settings and modules.
Reference Configure an ASP.NET Core App: The web.config file
Startup is your entry point into the application where you can have some settings in the json file and have your code add/update the configuration based on that.
My thinking is that it would save having to recompile every time you want to add something because configuration options allows you to Reload configuration data with IOptionsSnapshot
Requires ASP.NET Core 1.1 or later.
IOptionsSnapshot supports reloading options with minimal processing overhead. In ASP.NET Core 1.1, IOptionsSnapshot is a snapshot of IOptionsMonitor<TOptions> and updates automatically whenever the monitor triggers changes based on the data source changing. In ASP.NET Core 2.0 and later, options are computed once per request when accessed and cached for the lifetime of the request.
Your authorization handler(s) would depend on the options and perform its function based on the configurations provided.

ASP .Net Identity and Entity Framework Database

I'm developing an event page using entity framework and asp net identity 2.0 and I'm new also with this kind of tools.
If I create a new project that using template visual studio, it's automatically create a DB with several table. and also there are many code that I don't need in that template. (template -> project mvc with already installed authentication).
I've read several tutorial, but for creating from scratch my step is like this :
Create a DB
Create simple mvc project and install package nuget for asp net identity and EF framework
Set the connection strings
Create the code and EF will automatically created the table if not exist on DB?
I'm not really sure with number 4.. and are my steps are correct?
Thanks
Just follow the tutorial step by step, this will teach you how to create and build your project in a very simple way.
Getting started with ASP.NET Identity:
https://www.captechconsulting.com/blogs/Customizing-the-ASPNET-Identity-Data-Model-with-the-Entity-Framework-Fluent-API--Part-1
and here is a good Introduction to ASP.NET Identity:
http://tektutorialshub.com/asp-net-identity-tutorial-basics/

Cannot attach file as database in multiple projects

I have two projects which are targeting the same database. One of them is an MVC web application and the other is a Web API project. However, when I initialize an instance of the context in any of the projects I get the following exception:
Cannot attach the file 'myRoute/MyDatabase.mdf' as database
'MyDatabase'.
They way I have solved this is by:
Erasing my database from the SQL server object explorer (as stated in EF5: Cannot attach the file ‘{0}' as database '{1}')
Running code first migrations once again.
However, if I run the code first update while my startup project is the web application, the web services generate the same exception. If I run the code first update while my startup project is the web service, then the web application has the same issue.
What happens?
For what its worth I had this problem and apparently solved it by adding an explicit reference to the database in the MVC Web.config file EXCLUDING the AttachDbFilename clause:

Way to use Entity Framework with Classic Asp

In my company, we have almost all the systems running on classic asp with the logic layer in dlls made by vb6. We use sql server and it's used via stored procedures.
Recently I found how easy is to connect to a procedure using entity framework, and we are trying to avoid the usage of vb6, and for tests purposes, i create a project in .net similar to the ones we use in vb6 with entity framework connecting to the procedure, and generating the tbl and using regAsm to register the dll, I could use it in the classic asp, but when i try to access the method that access the procedure, it gives me the return:
No connection string named 'xEntities' could be found in the application config file.
Where xEntities is the name of my context.
We can't migrate everything to the asp.net because of the time, but it will be very good if we stop using vb6.
Any suggestions?
Thanks.
Have you tried creating a web.config file with the appropriate Entity Framework sections in your web site folder? It is possible to have a web.config in a folder with an ASP Classic web site.

Deploying Hybrid ASP.NET webform and MVC project on iis7 - MVC Routing does not work

Hi Stackoverflow,
Im trying to deploy a hybrid ASP.Net Webform/mvc-project onto iis7 but the mvc routing does not work.
This is what i have done so far:
Added all required mvc-related dlls.(i have double checked bin-catalog to make sure that everythings there on the deployed installation)
Added MVC wildcard by adding the IsapiModule handler to iis handler mappings.
The Server has .Net-Framework 3.5 SP1 installed.
The web site Managed pipeline mode set to classic
Our project requires the app pool to be running in none-integrated pipeline, but im not sure what MVC requires of the app pool, may i run ASP.NET MVC(2) in a none-integrated managed pipeline?
The web application loads and i want to use the MVC-routing to load javascript but the mvc routing does not responde to the request and instead Webforms gives us a 404-response,
this only happens when the project has been deployed onto the server.
Does anyone has a idea of why the ASP.Net MVC routing does not fire?
Thanks and Best regards,
Mikael
I found the error, the installer did not update production web.config,
so there was some missing mvc-required references,
i used this article to find out what was missing, it describes how to setup a hybrid WebForm/Mvc project in a simple way.
And now im able to run a hybrid webform/mvc-project on iis7 classic without any problem.