Requesting to controller throws 500 Internal error when deployed to azure - asp.net-mvc

I am deploying a web service on AZURE. In AZURE, i have a MYSQL db and i have fed its connection string to the web.config file. Its all working fine in the local environment. But when i deploy it to AZURE, controller don't work. Here are the screenshots of local and remote working scenarios. Also i have traced the remote log file of that request in the screenshot.
Here is the log file of this error (500)
While surfing through the internet, i came across a lot of solutions like using identity, to change authorization to none and so on. I am very confused right now as its been 2 days and i am still stuck in it. Right guidance will be highly appreciated.

I have found a solution to this problem. The problem was simple. As i added the reference of mysql.data.dll in the project, i forgot to add it inside my bin folder (by checking copylocal=true).
After that i updated the web.config file by adding these markups in the <system.web></system.web>Tags.
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient" />
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.8.3, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
I also enabled custom errors="off", in this way i was able to get production level errors on the deployed code. `

Related

Connection string problem when deploying ASP.NET MVC website to PLESK

I'm going through a basic tutorial for ASP.NET MVC based on this Microsoft Help document. The app displays books and authors from a database and allows for CRUD operations on that data. Everything is working fine on my machine when I run locally developing with Visual Studio 2017. But when I try to to deploy to my PLESK hosted website I'm having problems. I recreated (from scratch) a MySQL database designed to exactly replicate the schema of local database and populated it with sample values. When the page loads, I'm getting a long hang and ultimately a 500 error after it tries unsuccessfully to connect to the database.
This is the connection string that is working locally:
<add name="BookServiceContext" connectionString="Data Source=(localdb)\MSSQLLocalDB; Initial Catalog=BookServiceContext-20200803155333; Integrated Security=True; MultipleActiveResultSets=True; AttachDbFilename=|DataDirectory|BookServiceContext-20200803155333.mdf" providerName="System.Data.SqlClient" />
And here's the connectionStrings part of the remote web.config:
<add name="BookServiceContext" connectionString="Server=###.##.###.##;Database=BookServiceContext;Uid=myPLESKUserIDAssociatedWithDatabase;Pwd=PasswordForTheUser;multipleactiveresultsets=True" providerName="System.Data.SqlClient" />
Perhaps I have the syntax wrong or am missing a setting in PLESK (I was trying to use a sample from ConnectionStrings.com and haven't set up a DB in PLESK before).

Published website, but it now displays an error page instead of homepage

The error states:
An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.
Here's the address where you can see the error:
http://connellchamberofcommerce.com/
I have a feeling there's something in the web.config I'm supposed to change now that the website is online instead of my local machine, but this is my first ASP.Net website and I don't know what it is.
Is there something simple I'm missing that you're supposed to do when publishing an ASP.Net website?
In order to diagnose errors for your initial deployment, you can make the following change to your web.config.
<configuration>
...
<system.web>
...
<customErrors mode="Off" />
...
</system.web>
...
</configuration>
You should change this back to RemoteOnly when you have resolved all your deployment exceptions to prevent unsavory folks from learning too much about your architecture.

MVC 4 deployed to IIS 8 Page can't be Displayed

I am trying to deploy a MVC 4 application to IIS 8 on Windows Server 2012.
I am copying the files to the server by using Publish > File System.
I have created a new web site in IIS on the server, pointed this to the correct directory, but when trying to view the site I see 'This page can’t be displayed'.
I have never deployed an MVC application before, so may have missed something very simple.
After spending a lot of time searching on the Web, I have:
Ensured the correct version of .NET (4.0) is installed, and is selected within a new Application Pool created specifically for my app
Disabled Directory Browsing
Ensured the System.Web.MVC.dll is copied into the Bin folder
Added the following to web.config:
Below:
<modules>
<remove name="UrlRoutingModule-4.0" />
<add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="managedHandler" />
</modules>
I am very grateful for any help or suggestions!
Martin
Oh dear...it looks like the problem was caused by my using Port 110 in the web site bindings. I think this is a reserved Port.
Hope some of the bullets above help someone else anyway.

mvc 4 I've deployed to production server. Now cannot connect to localdb

I finally have a published website. Now I want to continue development so I changed my webconfig back to the previous working localdb connection string.
<add name="HouseContext" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=MVCBSV;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\MVCBSV.mdf" providerName="System.Data.SqlClient"/>
and then commented out the connection string to the production server.
<!--<add name="HouseContext" connectionString="Data Source=bstatus2014.db.10188888.hostedresource.com; Initial Catalog=bstatus2014; User ID=bstatus2014; Password=Bstatus!2014;" providerName="System.Data.SqlClient" />-->
But when I run the project, the data that is retrieved is the production data! I've tried clean and then build solution but no effect. Probably related, is that I published to the local IIS following the web deploy suggestions adding an application pool. Also if I use the connection wizard specifying localdb/v11.0 it no longer shows my MVCBSV.mdf db.
Also I was trying to use transforms debug/release to make this change, but have found a post that transforms don't work on debug.
A beginner so explicit answers are a help.
Yea, if you publish to your local IIS then your application is probably tied to that site. Open IIS, find the published site open the folder your published code is in and then look at the Web config it is associated to it. Also try recycling the app pool.
Transforms should only be used when you are publishing to a non-local environment anyway. Beyond that if you publish it might make more sense if you published to a location in your file system.

"Resource not found" error while accessing elmah.axd in ASP.NET MVC project

My ASP.NET MVC application is within a folder called Stuff within IIS 6.0 webroot folder. So I access my pages as http://localhost/Stuff/Posts. I had EMLAH working while I was using the in-built webserver of Visual Studio. Now when I access http://localhost/Stuff/elmah.axd, I get resource not found error. Can anyone point my mistake here! Here is config file entry,
<add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah"/> //Handler
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah"/>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah"/> //Module
Working with IIS7 I found I needed both sections of the web.config populated (system.web AND system.webServer) - see Elmah not working with asp.net site.
Perhaps this is related.
Have you added an ignore *.axd routes in global.asax?
For Elmah, we need to differentiate between two things:
First the http modules doing all the work of error logging, emailing...etc.
Second, the http handlers, displaying the error log page and other pages (rss...etc.)
I was having the same problem of 404 resource not found because I have a weird setup!
on my development machine, (windows 7, iis 7 ) elmah was working like a charm because the application pool was working in the integrated pipeline mode. In the production machine, however, the application was using the managed pipeline and I tried all my best to make elmah work but it was all useless...
I then got the idea of displaying the UI (error log page, rss, error detail,...) using regular aspx pages.
I downloaded the source code, made some changes (sorry Atif, I was forced to do this because I needed the quickest solution) and then in my application , I created a folder under which I created regular aspx pages which inherits from Elmah defined pages.
The page only contains one line (ex: for the detail page: <%# Page Language="C#" Inherits ="Elmah.ErrorDetailPage"%>)
Now, I was able to run Elmah regardless of IIS 6/7 and it is working like a charm.. and It saved me from a big headache of correctly configuring http handlers and troubleshooting its work! additionally, configuring security is much simpler!
I don't know if the community is interested in this solution (If so, I am ready to post my full changes).
Hope that this gives you an idea on how to solve the problem in an alternative way (and if you need the modified dll with complete instructions on how to use it, just tell me!)
In the application pool settings in IIS set Managed Pipelin Mode to Classic if you don't want to change code or the web.config file. Your axd.s will then work as before.
Can you post the rest of your web.config?
Or, if you're comfortable enough, can you just ensure that the httpHandlers and httpModules (NOT handlers and modules) sections are filled in properly in the web.config?

Resources