I have a MVC Project Which I want to Publish and upload it
I asked the server provider to upload my data base.
My Data base is local
and here is the information of this:
Name : vidiaweb_com_TourDbContext
DataBase: vidiaweb_com_TourDbContext-20160613111028
and here is my connection string
<connectionStrings>
<add name="vidiaweb_com_TourDbContext" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\vidiaweb_com_TourDbContext-20160613111028.mdf;Initial Catalog=vidiaweb_com_TourDbContext-20160613111028;Integrated Security=True;User Id=vidiaweb_com_TourDbContext;Password=password;" providerName="System.Data.SqlClient" />
</connectionStrings>
but in each page Which there is model for example like this
#model IEnumerable<vidiaweb_com.Models.Country>
, an error appeared:
'Server Error in '/' Application.
The system cannot find the file specified
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ComponentModel.Win32Exception: The system cannot find the file specified
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[Win32Exception (0x80004005): The system cannot find the file specified] '
Dose any one have any idea what may would be the problem?
Obviously, your web host is not putting the database in the /App_Data/ directory of your web site, which is what you are specifying in the connection string with |DataDirectory|\. It is likely being attached to a real SQL Server instance, in which case you won't specify a directory.
You need to obtain the server details of the database from your web host. Most likely your connection string will look something like this:
SERVER=data.somewhere.com;DATABASE=vidiaweb_com_TourDbContext;UID=TheApplicationUserName;PWD=TheApplicationPassword;
See ConnectionStrings.com for some more samples of what the connection string could look like.
Related
Nothing on Google or SO relates to this specific problem, so asking a new question. I created a brand new Asp.Net MVC Web Application with the standard user-security option. I also created an empty database in Azure.
I did nothing but change the default connection string to this:
<connectionStrings>
<add name="DefaultConnection"
connectionString="data source=mydatabase.database.windows.net;initial catalog=Feedback;persist security info=True;user id=LeaveFeedbackuser;password=mypassword;MultipleActiveResultSets=True;App=EntityFramework"
providerName="System.Data.SqlClient" />
</connectionStrings>
and the default connection factory to this:
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="v12.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
On attempting to register (when I would expect it to normally create the AspNetUsers and related tables) I get the following error:
The magic number in GZip header is not correct. Make sure you are
passing in a GZip stream. Description: An unhandled exception
occurred during the execution of the current web request. Please
review the stack trace for more information about the error and where
it originated in the code.
Exception Details: System.IO.InvalidDataException: The magic number
in GZip header is not correct. Make sure you are passing in a GZip
stream.
Source Error:
Line 153: { Line 154: var user = new
ApplicationUser { UserName = model.Email, Email = model.Email }; Line
155: var result = await UserManager.CreateAsync(user,
model.Password); Line 156: if (result.Succeeded) Line
157: {
What has any of this to do with GZip and what is causing this error? This has stopped me getting OWIN working with my Azure database for several days now.
I experienced a similar problem.
The Entity Framework __MigrationHistory Model column contains GZipped data. If the data in this column is corrupted then your app won't be able to unzip the data and you'll get the error.
In my case, the corruption occurred by trying to manually insert into this able.
My solution: delete corrupted __MigrationHistory rows and related DB changes and allow the app to migrate the database properly.
So here's my "theory". I think the Sql Azure Db is not setup correctly or the connection string is in error.
We know that when AspIdentity attempts to hit the database on Login and finds the tables are not set up it will try to create them.
I think there is a breakdown/bug in the AspIdentity code that under this circumstance swallows the exception generated from the bad connection string and thus the failed setup and continues on it's merry way trying to provide an authentication ticket to the client.
If we look into the code for Microsoft.Owin.Security.DataHandler.Serializer.TicketSerializer we find some GZip action:
public virtual byte[] Serialize(AuthenticationTicket model)
{
using (var memory = new MemoryStream())
{
using (var compression = new GZipStream(memory, CompressionLevel.Optimal))
{
using (var writer = new BinaryWriter(compression))
{
Write(writer, model);
}
}
return memory.ToArray();
}
}
So basically I think AspIdentity fails on the connection, this error is swallowed, the Owin pipeline continues processing the request but when it hits the TicketSerializer perhaps a null value or some other bogus value is passed in which Gzip tries to zip and Boom!
Weirdo YSOD output ensues.
The magic number in GZip header is not correct. Make sure you are
passing in a GZip stream. Description: An unhandled exception occurred
during the execution of the current web request. Please review the
stack trace for more information about the error and where it
originated in the code.
AspIdentity is not properly short circuiting OWIN request processing for this particular event.
Probably utter nonsense but I'll throw it out there anyway.
I'm working on my first real MVC project and my task is to implement a custom membership provider. I have implemented one before in asp.net 3.5 Web Forms so I'm trying to reuse some of that code if possible.
Our data comes from a remote web service so I won't be using any of the standard membership database.
Based on some research and experience in Web Forms I created my class:
public class wwdllMembershipProvider : MembershipProvider
I put the following in web.config:
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="2880" />
</authentication>
<membership defaultProvider="wwdllMembershipProvider" userIsOnlineTimeWindow="15">
<providers>
<add name="wwdllMembershipProvider" type="wwdllMembershipProvider" enablePasswordRetrieval="false" enablePasswordReset="false" writeExceptionsToEventLog="false" enablePasswordChange="true" />
</providers>
</membership>
From there I was just going to try to see if any of the stubbed out code in my membership provider was being hit. But as soon as I click on the login link in the app I get the following error:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
Source Error:
Line 55: using (var context = new UsersContext())
Line 56: {
Line 57: if (!context.Database.Exists())
Line 58: {
Line 59: // Create the SimpleMembership database without Entity Framework migration schema
Source File: c:\Users\mburt\Documents\Visual Studio 2012\Projects\eSales\4300\Siriusware.eSales\Filters\InitializeSimpleMembershipAttribute.cs Line: 57
Which is puzzling to me because I didn't think the Simple Membership Provider code would execute because of the web.config setting disabling it.
Can someone point out to me what I'm doing wrong? Thanks!
The default account controller is decorated with that very attribute. Check if that is still present.
(Default MVC4 project code below.)
namespace MvcApplication2.Controllers
{
[Authorize]
[InitializeSimpleMembership]
public class AccountController : Controller
{
[...]
}
}
I'm trying Windows Azure to host an MVC4 web application.
I've created a test app, using VS2012 MVC4 internet application template and added a custom Model and Controller to it.
I've published it on Azure and managed to get 'update-database' apply migrations to the Azure Database.
When i try the app locally, but using the Azure SQL database, it works fine.
I can login/register and use my test controller.
When i try the app online, i can use the test controller but login or register links give the following exception:
Server Error in '/' Application.
The "WebSecurity.InitializeDatabaseConnection" method can be called only once.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: The "WebSecurity.InitializeDatabaseConnection" method can be called only once.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[InvalidOperationException: The "WebSecurity.InitializeDatabaseConnection" method can be called only once.]
WebMatrix.WebData.WebSecurity.InitializeMembershipProvider(SimpleMembershipProvider simpleMembership, DatabaseConnectionInfo connect, String userTableName, String userIdColumn, String userNameColumn, Boolean createTables) +123
WebMatrix.WebData.WebSecurity.InitializeProviders(DatabaseConnectionInfo connect, String userTableName, String userIdColumn, String userNameColumn, Boolean autoCreateTables) +51
WebMatrix.WebData.WebSecurity.InitializeDatabaseConnection(String connectionStringName, String userTableName, String userIdColumn, String userNameColumn, Boolean autoCreateTables) +52
MembershipTest2.Filters.SimpleMembershipInitializer..ctor() +193
Do you have any idea where that comes from ?
If i debug (the local version), this method is only called once.
Thanks.
You could try encapsulating the call(s) to that method to ensure it's not called more then once
if (!WebMatrix.WebData.WebSecurity.Initialized)
{
WebSecurity.InitializeDatabaseConnection(...);
}
in my case I had both
(in web.config)
<add key="enableSimpleMembership" value="true" />
and
(in _ViewStart.cshtml)
WebSecurity.InitializeDatabaseConnection("club", "Account", "UserID", "UserName", autoCreateTables: true);
Solution: it seems you cannot have both, so remove one
Does the following SO discussion help you?
Cannot seed Users & Roles
I did find the following article helped me lot to use newer MVC4 & EF together with Simple Membership Provider so if you haven't read it please take a look:
SimpleMembership, Membership Providers, Universal Providers and the new ASP.NET 4.5 Web Forms and ASP.NET MVC 4 templates
I have the following code that retrieves a link to the latest post from the blog subsite:
XDocument doc = XDocument.Load("http://www.mysite.com/blog/syndication.axd");
XElement node = doc.Descendants("item").FirstOrDefault();
string text = node.Element("title").Value;
string uri = node.Element("link").Value;
The code always worked fine. This week I added ELMAH.MVC via NuGet as a Package Reference. As soon as I deploy the web.config file with the added ELMAH sections, I get the following error:
System.Web.HttpException (0x80004005): Error executing child request for handler
'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'.
---> System.Net.WebException: The remote server returned an error: (500) Internal Server Error.
at System.Net.HttpWebRequest.GetResponse()
at System.Xml.XmlDownloadManager.GetNonFileStream(Uri uri, ICredentials credentials, IWebProxy proxy, RequestCachePolicy cachePolicy)
at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials, IWebProxy proxy, RequestCachePolicy cachePolicy)
at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn)
at System.Xml.XmlReaderSettings.CreateReader(String inputUri, XmlParserContext inputContext)
at System.Xml.XmlReader.Create(String inputUri, XmlReaderSettings settings, XmlParserContext inputContext)
at System.Xml.Linq.XDocument.Load(String uri, LoadOptions options)
If I put the old web.config file back, the error goes away.
Any idea why adding ELMAH would cause XDocument.Load to fail?
You need to look at your ASP.Net site and find the server-side error.
I'm trying to display an image using Lightbox with the logic something like this:
public ActionResult displayImg()
string lbx = "";
return View (lbx);
But it gives an error:
Server Error in '/' Application.
--------------------------------------------------------------------------------
Illegal characters in path.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: Illegal characters in path.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
You're passing <a ...></a> as a view name, which is translated into a filename in your project.
That's not a valid filename.
You probably want to return Content(...), which returns a literal string.
You also need to map the path using the URL class.