This is my web.config SQL:
<connectionStrings>
<add
name="UsersDB"
connectionString="Server=MYSQL5008.myWindowsHosting.com;Database=db_9b443f_users;Uid=9b443f_users;Pwd=YOUR_DB_PASSWORD;"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<membership defaultProvider="SqlProvider"
userIsOnlineTimeWindow="15">
<providers>
<clear />
<add
name="SqlProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="UsersDB"
applicationName="MyApplication"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="true"
requiresUniqueEmail="true"
passwordFormat="Hashed" />
</providers>
</membership>
<compilation debug="true" targetFramework="4.0" />
</system.web>
Can you tell me what's wrong here please? Thanks!!
And don't mind the 'YOUR_DB_PASSWORD', I just changed it so I can show you the code..
Given that your appear to be connecting to an external server
MYSQL5008.myWindowsHosting.com
ensure that there is an appropriate firewall rule in place to allow the SQL server connection through. The default port is 1433.
There are quite a few other configuration items to check in general, but since this appears to be a hosted SQL solution the firewall is by far the most likely.
UPDATE
As noted by #Steve, is this a SQL Server or MySQL database? If MySQL, you need to change the provider name in your configuration. See
http://dev.mysql.com/doc/connector-net/en/connector-net-tutorials-asp-roles.html
for details.
Related
I have tried to host the core project with mdf file in the IIS server. The below webconfig file works fine in the localhost. But when I publish it to IIS, I got a 500-internal server error.
This is the webconfig:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.entit, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="FileManagerConnection" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|App_Data\FileManager.mdf;Integrated Security=True;Connect Timeout=30" />
</connectionStrings>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824"></requestLimits>
</requestFiltering>
</security>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" arguments="%LAUNCHER_ARGS%">
<environmentVariables />
</aspNetCore>
</system.webServer>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
LocalDB is a database instance provided by the Visual studio. In order to make it work in IIS properly, we should start the Visual Studio and change the application pool identity to the specific account that running the Visual studio. But this is not a common way to publish the database, we should add database immigration to the current project so that we publish the database to the remote database server.
Here is an example of database immigration from localdb to a remote SQL server.
How to transfer ASP.NET MVC Database from LocalDb to SQL Server?
Feel free to let me know if there is anything I can help with.
The .mdf files are SQL Server database files. No other application can understand, read, or update those files. So, I have installed the SQL server in my machine and then host the core project in IIS.
As title, I want to disable Anonymous Authentication for my ASP.NET Boilerplate web site (MVC) in IIS Server and use Form Authentication instead. Is it possible to do this because if I disable Anonymous Authentication, my website cause an error "HTTP Error 404.15 - Not Found"
Update 1: Here is my web.config
<system.web>
<globalization culture="auto" uiCulture="auto" />
<compilation debug="true" targetFramework="4.6.1">
<assemblies>
<add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</assemblies>
</compilation>
<httpRuntime targetFramework="4.5.1" />
<customErrors mode="Off">
<error statusCode="404" redirect="~/Error/E404" />
</customErrors>
<httpHandlers>
<add path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" validate="false" />
</httpHandlers>
<authentication mode="Forms" />
</system.web>
I still remember the first time I had to implement Forms Authentication in ASP. All I can say is there is a reason I only do linux based web-development now!
It is a real pain, but this should work if you don't intend on using a database to manage the users.
If you do intend to use a database then prepare yourself for a long road. U need to have the correct MSSQL database for the correct Visual studio tool and they also removed the management interface completely so you either have to design your own or use a tool that is available on the internet somewhere. I still remember I got so frustrated by the whole idea of it, that I literally wrote my own management tool I could deploy on developed sites. If it wasn't on a broken harddrive I would give it to you.
<authentication mode="Forms">
<forms loginUrl="login.aspx" defaultUrl="welcome.aspx">
<credentials passwordFormat="Clear">
<user name="abhishek" password="abhi#123"/>
<user name="Kantesh" password="sinha#123" />
</credentials>
</forms>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
If you plan on using a database to store your users google some tutorials.
The reason why you are getting a 404 is because you are not specifying loginUrl or it is incorrect and pointing to a non-existant page.
Hope this helps
When you disable anonymous access to all pages you cannot let users to see login page as well. what you need to to do is allowing some specific pages like login or register to be accessible.
This might not completely fits for you but you get the idea.
If it doesn't work, try removing the backslash "/" for the "/account/login" and set it like "account/login"
<configuration>
<system.web>
<authentication mode="Forms" />
<authorization>
<deny users="?" /> //this will restrict anonymous user access
</authorization>
</system.web>
<location path="/account/login"> //path here is path to login page
<system.web><authorization><allow users="*" /> // this will allow access to everyone to login page
</authorization></system.web></location>
</configuration>
I'm starting with Asp.net MVC. When connect to SQL Server database then error.
This is <connectionStrings>
<add name="SGTSVNDBContext" connectionString="Data Source=DESKTOP-ABKAVRM\SQLEXPRESS;Initial Catalog=SGTSVNDBAUTH_CusCloud;Persist Security Info=True;User ID=sa;Password=;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
This is <appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="DefaultPassword" value="123456" />
<add key="CustomerKey" value="YN8HgQuslP7kHfMeJk0NyHbu1R2IyHo4neUWmIHlffA=" />
<add key="GCM-SENDER-ID" value="86033830857" />
<add key="AUTH-TOKEN" value="AIzaSyB3FLcWcrRlOcu_zyCdl6tMawlvSoX4MeQ" />
<add key="FCM-SENDER-ID" value="122441061332" />
<add key="FCM-SERVER-KEY" value="AAAAHIIOU9Q:APA91bGWrJHwfJKiZsRGs8V62_xhuK9x0AWDNewrEnQiPrsrIpZ2YVYKop4Z44LSdNv_iZcSFmHpQ8YxS-WrTniZ5cZMe5T85PKJzv-CTNjTikwc7rqwoIXU--Ssk84IdmBzM8XcYuBb" />
<!--<add key="BackupPath" value="\\192.168.2.10\SGVN-Server\Scan folder\Phat\" />-->
<add key="BackupPath" value="D:\Mine\SystemGear\SGVN_SGF #07_2015\Project\Sites\WebAPI\Database_Backup\" />
<add key="SqlInstanceName" value="SGSOFT09-V2" />
<add key="BackupDBName" value="SGTSVNDBAUTH_CusCloud" />
<add key="SqlUserName" value="sa" />
<add key="SqlPassword" value="" />
When build project then error as the this
You have no password in your connection string, therefore it is failing to login to the database.
If you are sure the SQL Server is in "mixed mode", and that the password is correct for the "sa" account, I can only suggest it to be that the "sa" user doesn't have access to the named database.
In SQL Management Studio, expand the database branch, then security, then users, and check if the "sa" user appears in the list.
The best way to diagnose this error is to try and connect to the database server using SQL Management studio, logging in AS the user in the connection string.
If you can log in, see if you can see your target database in the tree on the left.
Try it with SQL Management Studio from the same machine you're code is running and it should give you more information about what's wrong.
Try changing your connection string to the following:
If the connection string is correct then check for the key value of connection string used in entity framework class.
My server which hosts my IIS site has just rebooted, now when i navigate to my internal site, im getting a 401 challenge, it should be windows integrated. it doesnt accept credentials either.
below is the current config, it all worked prior to the reboot and i havent changed any code since. any ideas?
Thanks
webconfig
<system.web>
<globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="en-GB" />
<authentication mode="Windows" />
<identity impersonate="true" />
<authorization>
<deny users="?" />
</authorization>
<roleManager enabled="true" defaultProvider="AspNetWindowsTokenRoleProvider">
<providers>
<clear />
<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
</providers>
</roleManager>
<customErrors mode="Off" />
<compilation debug="true" targetFramework="4.0">
IIS Settings
Authentication
Anyon: Enabled
ASP.net Imper Enabled
Windows Auth Enabled
Application Pool
.net 4.9
Managed pipeline intergrated
identity applicationpoolidentity
I fixed this. my server needed an SPN adding
Setup:
For an ASP.NET MVC 4 app I am using Elmah.MVC 2.0.1 to log errors.
I installed Elmah.MVC using NuGet. It works fine.
Problem:
The Elmah.MVC package installs no controller or area, so I can see no obvious way to apply security via Authorize attributes, as is recommended for ASP.NET MVC.
Question:
I only want users in the Admin role to be able to view the Elmah page.
How do I do this?
Ouch!
Just found the answer;
Elmah MVC 2.0.1 NuGet package adds the following into <appSettings> (in web.config):
<add key="elmah.mvc.requiresAuthentication" value="false" />
<add key="elmah.mvc.allowedRoles" value="*" />
To achieve what I want simply:
<add key="elmah.mvc.requiresAuthentication" value="true" />
<add key="elmah.mvc.allowedRoles" value="Admin" />
I believe you can also use URL access control like this:
<location path="elmah.axd">
<system.web>
<httpHandlers>
<add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
</httpHandlers>
<authorization>
<allow roles="YourRole" />
<deny users="*" />
</authorization>
</system.web>
<system.webServer>
<handlers>
<add name="ELMAH" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode" />
</handlers>
</system.webServer>
</location>