Configuring roleManager provider with MVC Error - asp.net-mvc

I always get an error when running my MVC Project since I put
this code on my web.config file.
<roleManager defaultProvider="CustomRoleProvider" enabled="true" cacheRolesInCookie="false">
<providers>
<clear />
<add name="CustomRoleProvider" type="SM.MyRoleProvider" />
</providers>
</roleManager>
This is what my error looks like :
Configuration Error
Description: An error occurred during the processing of a
configuration file required to service this request. Please review the
specific error details below and modify your configuration file
appropriately.
Parser Error Message: This method cannot be called during the
application's pre-start initialization phase.
Please can someone tell me whats going on ?

Hi you must be go to in visual studio and go to path:
website tab -> ASP.NET Configuration ->security tab -> disabled role

Related

Intercept elmah logging ASP.NET MVC [duplicate]

This question already has an answer here:
elmah error handling - store in database
(1 answer)
Closed 6 years ago.
I would like to try to intercept and do some other processing ( export a database ) when elmah raises an error.Is there a way to do that?
ELMAH exposes two events in order to do this: ErrorLog_Filtering and ErrorLog_Logged. ErrorLog_Filtering is called just before logging to the configured error log and ErrorLog_Logged is called just after. You will find documentation about error filtering on the ELMAH site. ErrorLog_Logged isn't really documented, but you can see an example of it in this article: Logging to multiple ELMAH logs.
With that said, you probably don't want to execute any long running tasks as part of ErrorLog_Logged and ErrorLog_Filtering. It will slow down your system. I'm not sure on what you are trying to achieve here by exporting a database on every error?
Yes there is way around
1.Lets Create a Project Name ElmahMvc
2.Install nuget package nuget
Install-Package Elmah.MVC
3. Raise an Exception .There you go access error log by your local url/elmah
http://localhost:20351/elmah
The saving database and Emailing is bit of configuration to take ....
Lets look at it
1.Download ELMAH script form official site
ELMAH
2.add a database named log and run the script
3.add a connection string in web.config
<connectionStrings>
<add name="elmah" connectionString="Data Source=.;Initial Catalog=log;Persist Security Info=True;User ID=sa;Password=pass" providerName="System.Data.SqlClient" />
</connectionStrings>
4.Add a elmah element in web.config
<elmah>
<errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="elmah" />
<!--For Addtional Mail Config .Remove it if not need for mail on every error-->
<errorMail from="waltoncrm#waltonbd.com"
to="mrahman.cse32#waltonbd.com"
subject="Application Exception"
async="false"
smtpPort="25"
smtpServer="YourServer"
userName="uName"
password="pass">
</errorMail>
</elmah>
and mail additional
under System.WebServer
<system.net>
<mailSettings>
<smtp deliveryMethod ="Network">
<network host="smtp.gmail.com" port="587" userName="yourgmailEmailAddress" password="yourGmailEmailPassword" />
</smtp>
</mailSettings>
</system.net>
Download my sample project and Elmah script with Visual Studio 2013
akash365.com
Note:if you donot want to crash your program or use it in asp.net web form Static [WebMethod]
This seems perfect
try
{
//some web method code
}
catch(Exception ex)
{
Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
}

MVC Controllers - Connection String / associations - No Connection String could be found in the application config file

Please excuse me is this is a noob question. I have a MVC project with a number of EF Database first models. When I created them some were created with new connection strings.
I have tried to clean up the project web.config file and commented out the duplicated connection strings,
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=........... />
<add name="DB_A09819_ProductsEntities" connectionString="metadata=........... />
<add name="DB_A09819_PowerDB001Entities" connectionString="metadata=........... />
<!--
<add name="DB_A09819_ProductsEntities_IntranetDownload" connectionString="metadata........... />
<add name="DB_A09819_ProductsPricing" connectionString="metadata=........... />
<add name="DB_A09819_ProductsProjectProposal" connectionString="metadata=.......... />
<add name="DB_A09819_ProductsProposalSystem" connectionString="metadata=........... />
-->
</connectionStrings>
I had thought that MVC would have picked up on the changes and raised errors, however with these changes the project builds and runs on development server.
When I try to add a controller I now get an error that the
---------------------------
Microsoft Visual Studio
---------------------------
Error
There was an error running the selected code generator:
'Unable to retrieve metadata for 'web...............t'.
No connection string named 'DB_A09819_..........'
could be found in the application config file.'
---------------------------
OK
---------------------------
I would like to change the associations and fix the connection string to have a single connection to each of the databases.
There are a number of posts where the solution is to add a connection string, I am trying to clean up my code and remove duplicate connection strings.
How do I change the association to the connection string in the Model and the controllers to ensure that it will run when deployed ?

Session is not working in windows server 2008 r2

I am trying to create a session on MVC application
string roleName="Raj"
Session.Add("UserRole", roleName);
But in server i found that it throwing error as
Object reference not set to an instance of an object(I'm unable to create session in server)
Solutions i tried:
Administrator tools -> ASP.NET State Service -> Started
Please help me..
Is there any settings need to set on web.config
Do you have any reference to sessionState in your web.config file? If not, try this:
<configuration>
...
<system.webServer>
...
<modules>
<remove name="Session" />
<add name="Session" type="System.Web.SessionState.SessionStateModule"/>
...
</modules>
</system.webServer>
</configuration>
First, go to IIS.
Select Your Web Site
Select the Basic Setting in the right panel.
Select Connect as.
Select User Have permission to Site Folder

how to set the Databse connection string in Web.config file in Asp.Net MVC2

Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: Sections must only appear once per config file. See the help topic for exceptions.
<connectionStrings>
<add name="testEntities" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string="Data Source=ROCKER\SQLSERVER2008;Initial Catalog=test;User ID=sunny;Password=sunnyconnected;MultipleActiveResultSets=True""
providerName="System.Data.EntityClient" />
<add name="DbConnection" connectionString="Data Source=Test\sqlserver2008;database=test;User ID=sunny;Password=sunnyconnected" providerName="System.Data.SqlClient"/>
This Connection String Set in Root Web.config File then it give runtime Above Mention Error.How it Can be Handle And Set in Asp.Net MVC2.
"connectionStrings" section should appear only once in a config file. Check if you have added it twice.

ASP.Net SQLExpress: Cannot open user default database. Login failed

I have 2 SQL express databases: one for my application data and another for the MembershipProvider data. When I attempt to use the CreateUserWizard control, I get the following error:
Error: Login failed for user 'SFP\Susan'.
I can connect to thesee the DB in the server explorer and all its tables and data. What is the problem?
Thanks in advance
It sounds like the MembershipProvider connection is not correctly set up in your web.config file. It should look something like this (with "MyAwesomeDatabaseConnectionName" being the name of the configured connection string, in the connectionStrings section of the file):
<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="MyAwesomeDatabaseConnectionName"
applicationName="MyAwesomeApp"/>
</providers>
</membership>
Also, it looks like you are configured for Windows authentication, but if your membership data is in a database, you'll want to configure for Forms authentication:
<authentication mode="Forms">
<forms loginUrl="~/myloginpage.aspx"
defaultUrl="~/myhomepage.aspx" />
</authentication>

Resources