Using a view specific connection string in ASP.NET MVC - asp.net

I upgraded an old website from ASP.NET to MVC recently and now I am running into a user login problem with one of my views. In the old situation I would have a separate web.config in the folder for that page that would set the connection string specifically for that page. Now I would like to do that in ASP.NET MVC as well, however the web.config in the specific views folder does not work. I also tried to change the web.config in the views folder, but maybe I did this in a wrong way because it did not work.
Does anyone have an idea how to accomplish the same result in ASP.NET MVC as I had in ASP.NET?

Why not use a separate configuration file, as explained in this MSDN article?
https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/connection-strings-and-configuration-files

Related

Allow HTML files in Asp.Net MVC application

I'm building an application using ASP.NET MVC and Angular JS.
The point is to use angular for all web things and ASP.Net for backend stuff. In other words, I kind of bypassed the whole view of MVC and used a single view. Angular will get his files from the Content folder.
Those files are .html files and this seem to be a problem because I always get a 404.
Actually I also tried renaming it to .cshtml but that does not fix the problem..
Do you know of any tricks (well, clean ones of course) to let my angular app download it's views and be happy?
Thanks.
Georges
The problem most likely is in the fact that ASP.NET MVC tries to filter the request through the routing mechanism, and obviously there is no route for HTML files. Try adding the following to the routes registration method:
routes.IgnoreRoute("{file}.html");

ASP.net MVC Routing problem

I have deployed my ASP.net MVC site to a shared hosting company. The problem is that now none of the pages except for the home page work. For example if I go to /Account/Register I get a page not found. However, if I go to /Account/Register/Index.aspx then it does work. I have tried modifying the routing to add in that index.aspx but everything I have tried fails.
Sounds like you need to either
1) have a wildcard mapping set up in IIS (don't know if thats an option)
2) or setup the routes to include the extension ("{controller}.mvc/{action}/{id}").
Either way have a look at this post by Phil Haack: ASP.NET MVC on IIS 6 Walkthrough

asp.net MVC Routing Problem

Someone has asked me to look at their code to do a few little changes to the processing, but before I can get anywhere, I can't even run up the main page. It seems to be MVC, seems to have the right routes etc. It defaults to a ~/home from default.aspx and there seems to be a route in place, but I get a 404.
I've tried changing the route and it still fails. I've debugged and it seems to be setting the routes up. I've set up Phil Haack's debug utility but it still just gives me a 404.
I'm quite new to asp.net MVC, but I've done asp.net and know some MVC (CakePHP) and I'm not really working with the MVC, just some processing code. Are there any big "gotchas" I should be looking for?
There is a Default.ASPX page that is included in the root path by default in all ASP.NET MVC projects. It has a comment in it that says:
Please do not delete this file. It is
used to ensure that ASP.NET MVC is
activated by IIS when a user makes a
"/" request to the server.
You might want to check and see if it is still there.
Are you running the app on IIS 6? If so, the problem is that IIS only invokes ASP.NET when it sees a .aspx extension in the URL. This can be fixed in a number of ways, described, for instance, here and here. I solved the problem changing IIS options to use aspnet_isapi.dll for all files (that is, *).
The problem was that the project was built on asp.net MVC Preview, and I already had asp.net MVC v1 installed, which seemed to create some sort of conflict.
I've removed asp.net MVC and the problem has gone away.

ASP.NET Routing not firing when site is published to remote host

I have a website that was originally written in webforms to which I have added MVC functionality. When debugging locally it works fine, however, once published and uploaded to my host the routes do not work and return a 404.
I am pretty sure that I have uploaded all the correct files. Would just appear that routing is not working.
Any idea?!
(the site will still serve normal aspx pages fine)
I think the problem may be related to Mixing ASP.NET MVC into ASP.NET WebForms
But I cant see from that thread what the solution was. It looks like it might be something to do with the app_pool mode - but I am running in integrated mode, which is right AFAIK
UPDATE 2
So I think I have routing working. I basically created a new MVC app and went through theweb config file line by line and made sure I have everything I needed. Funnily, none of the tutorials online mention the correct additions you need to make. hey ho..
I have have another issue mind you...
When i load my mvc page I am greeted with the message:
The SessionStateTempDataProvider requires SessionState to be enabled.
I've added a line to web.config to enable sessions (wasn't aware they were off) and it still doesnt work.
UPDATE
I created a new asp.net MVC project and ended up going through web.config line by line and ensuring that everything that related to MVC was included in my hybrid app. Suffice to say that none of the guides mention all the settings that are required (i was using the book professional asp.net mvc 1.0). I then included the global.asax file which is not published and set up a route so that a request for / was not being caught by MVC. I also had to enable sessions in web.config.
And now it works!
Should I mark this question as the answer...not sure on the protocol here :)
I was going through the same thing because I deploy with compiled views. I don't know why but global.asax isn't included in the Release folder that I uploaded. I just figured it was compiled into one of the DLLs. I was getting 404 for everything so I tried uploading global.asax and the site came to life.

Hybrid MVC and Web Site application

I evaluating the MVC framework for my existing application. Trying to write a sample applicaiton where I need to navigate from MVc view to .aspx files and vice versa. The application does seems to be working. Not able to figure out where I am going wrong.
I have set up wild card mapping
I have set up .mvc mapping
I am using IIS6
I am using VS2008 with SP1
I added Controller directory to App_Code
I added Views directory to the web site application
MVC does not seem to be working well with web site application.
I do not know where to activate .mvc ? I do not know where to write the following code
HttpContext.Current.RewritePath(Request.ApplicationPath, False)
Dim httpHandler As IHttpHandler = New System.Web.Mvc.MvcHttpHandler()
httpHandler.ProcessRequest(HttpContext.Current)
HttpContext.Current.RewritePath(originalPath, False)
Can some one help me? I do not know how can I give my code so that you could review that.
This code would go into the Page_Load method in the code behind of the Default.aspx in the root directory.

Resources