|
Brother this is error showing in this way "Line no. 22 con.open();
Server Error in '/' Application.
Database 'C:\Program Files (x86)\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\LoginDB1.mdf' already exists. Choose a different database name.
Cannot attach the file 'C:\Users\Atta\Documents\Visual Studio 2012\WebSites\WebSite3\App_Data\aspnet-WebSite3-20170707151050.mdf' as database 'LoginDB1'.
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: Database 'C:\Program Files (x86)\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\LoginDB1.mdf' already exists. Choose a different database name.
Cannot attach the file 'C:\Users\Atta\Documents\Visual Studio 2012\WebSites\WebSite3\App_Data\aspnet-WebSite3-20170707151050.mdf' as database 'LoginDB1'.
Source Error:
Line 20: {
Line 21: SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connect"].ToString());
Line 22: con.Open();
Line 23: string query = "select count(*) from userlogin where username ='" + txtBox1.Text + "'and pass '" + txtBox2.Text + "'";
Line 24: SqlCommand cmd = new SqlCommand(query, con);
Source File: c:\Users\Atta\Documents\Visual Studio 2012\WebSites\WebSite3\Default2.aspx.cs Line: 22
Stack Trace:
[SqlException (0x80131904): Database 'C:\Program Files (x86)\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\LoginDB1.mdf' already exists. Choose a different database name.
Cannot attach the file 'C:\Users\Atta\Documents\Visual Studio 2012\WebSites\WebSite3\App_Data\aspnet-WebSite3-20170707151050.mdf' as database 'LoginDB1'.]
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling) +821
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +332
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) +38
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +699
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +89
System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +426
System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +78
System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +191
System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +154
System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +21
System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +90
System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +217
System.Data.SqlClient.SqlConnection.Open() +96
Default2.Button1_Click(Object sender, EventArgs e) in c:\Users\Atta\Documents\Visual Studio 2012\WebSites\WebSite3\Default2.aspx.cs:22
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9819334
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +204
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +12
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +15
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1639
|
|
|
|
|
|
How do I build an XML based News page in ASP.NET MVC? I would like to enumerate XML files inside a folder and build a list of summaries on the page. Once the visitor clicks on one of the summaries, I would like to load the associated XML file and render the full news content (with nice formatting included).
An example of the summaries page can be found [1] while and example of the single XML news page rendered can be found here [2]?
Should I write everything from scratch or there is a good tutorial to start with somewhere?
Thanks.
[1]:https://www.devexpress.com/Home/Announces/2017-Universal-17-1.xml
[2]:https://www.devexpress.com/Home/Announces/
|
|
|
|
|
It depends on the structure of the XML files. Do they all share the same structure? If not, how do you identify which structure each file has?
If they're RSS or Atom feeds, the SyndicationFeed[^] class is probably the best place to start:
Build an RSS reader in 5 minutes | Thomas Levesque's .NET blog[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
XML file will be manually created by us and they should support formatting in some way. As you can see from the links, this News are nicely formatted (I mean titles, sub-titles, etc.)
Thanks.
|
|
|
|
|
We are getting complaints from the customer that they have to keep on refresh (Ctrl+F5) on the page or sometimes clear the cookies to reflect the changes done on upgrade.
Especially, when we upload CSS/JS files or Images sometimes.
To overcome this situation, I did some research and found one solution to append Query string with the name of image or CSS files. But it does not seem to be a coherent solution. Then I used NuGet packages for Bundle. It seems to be the solution but I have another issue like I am calling individual CSS file for each page (page specific) and to make a bundle for the single file is not the good idea.
What should i follow as good approach to overcome this situation where changes can reflect on the server after uploading CSS/Images or JS files.
|
|
|
|
|
You've already mentioned it, a querystring variable on the css\js paths.
|
|
|
|
|
Should I go with this option only?
|
|
|
|
|
|
Okay, I will opt the same.
Thanks
|
|
|
|
|
Mads Kristensen wrote a blog post explaining how to do this back in 2014: Cache busting in ASP.NET[^]
However, I'd be inclined to use the query-string rather than a fake path. It's a fairly simple change:
using System;
using System.IO;
using System.Web;
using System.Web.Caching;
using System.Web.Hosting;
public class Fingerprint
{
public static string Tag(string rootRelativePath)
{
if (string.IsNullOrWhiteSpace(rootRelativePath)) return string.Empty;
if (rootRelativePath[0] != '~')
{
rootRelativePath = "~" + rootRelativePath;
}
string result = HttpRuntime.Cache[rootRelativePath] as string;
if (result == null)
{
string absolute = HostingEnvironment.MapPath(rootRelativePath);
DateTime date = File.GetLastWriteTime(absolute);
result = rootRelativePath + "?v=" + date.Ticks;
HttpRuntime.Cache.Insert(rootRelativePath, result, new CacheDependency(absolute));
}
return result;
}
}
<link rel="stylesheet" href="@Fingerprint.Tag("~/content/file.css")" />
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Wasn't there some other setting that automatically forces updates the CSS?
|
|
|
|
|
Only if you disable caching on the files, which will degrade the performance of your site.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
This is a nice ASP.NET UrlRouting tool I have ever tried nowadays. I developed an asp.net web form app using this tool. It's great working my local IIS. If I deploy to my web hosting, it's giving an error about SecurityPermission. Please help me!
[SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
System.Web.Security.UrlAuthorizationModule.CheckUrlAccessForPrincipal(String virtualPath, IPrincipal user, String verb) +42
Microsoft.AspNet.FriendlyUrls.Abstractions.UrlAuthorizationModuleWrapper.CheckUrlAccessForPrincipal(String virtualPath, IPrincipal user, String verb) +14
Microsoft.AspNet.FriendlyUrls.FriendlyUrlRoute.GetWebObjectFactory(HttpContextBase httpContext, String modifiedVirtualPath) +159
Microsoft.AspNet.FriendlyUrls.FriendlyUrlRoute.Resolve(HttpContextBase httpContext, IList`1 extensions, String virtualPathOverride, IFriendlyUrlRouteSupportFunctions supportFunctions) +220
Microsoft.AspNet.FriendlyUrls.FriendlyUrlRoute.Microsoft.AspNet.FriendlyUrls.Abstractions.IFriendlyUrlRouteSupportFunctions.Resolve(HttpContextBase httpContext, IList`1 extensions, String virtualPathOverride) +16
Microsoft.AspNet.FriendlyUrls.FriendlyUrlRoute.GetRouteData(HttpContextBase httpContext, String pathOverride, IFriendlyUrlRouteSupportFunctions supportFunctions) +140
Microsoft.AspNet.FriendlyUrls.FriendlyUrlRoute.GetRouteData(HttpContextBase httpContext, String pathOverride) +9
Microsoft.AspNet.FriendlyUrls.FriendlyUrlsModule.RedirectToFriendlyUrl(HttpContextBase httpContext, IFriendlyUrlRoute route, IVirtualPathUtility virtualPathUtility) +346
Microsoft.AspNet.FriendlyUrls.FriendlyUrlsModule.<Init>b__0(Object sender, EventArgs e) +171
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +141
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69
|
|
|
|
|
|
often we attach role with action like below way
[Authorize(Roles = "Admin, SuperUser")]
[Authorize(Users="Jacquo, Steve", Roles="Admin, SuperUser")]
Users : Comma-separated list of usernames that are allowed to access the action method.
Roles : Comma-separated list of role names. To Access the action method, users must be in at least one of these roles.
[Authorize(Roles = "Producer")]
[Authorize(Roles = "Admin")]
public ActionResult Details(int id) {
}
now see authorize and role name is hard coded with action method. suppose action Details is associated with admin role which is hard coded but how could i attach more role to details action or remove any role from details action at run time. i guess it is not possible because asp.net mvc not providing anything built in.
i search google to see that anyone does it anything such as what i am looking for. unfortunately found no similar write up.
so i need some guidance that how could i develop a UI from where admin can associate role with action instead of hard coding at development time.
so tell me your think how could i associate a role or multiple roles with action from a custom UI.
also tell me how could i check at run time that user has that role when user try to access a specific action.
please discuss in details for designing this part what i am looking for. still it is not clear to you what i am looking for then tell me i will try to explain the same in more details.
thanks
|
|
|
|
|
I think these can't be dynamic due to the fact that .net only inistialises the attribute the once and as the valid roles\users are set on initialisation they are set forever once created. To do what you want to do you'll probably need to write your own validation attribute that gets the list of valid users\roles from some other location rather than the attribute parameters. I'm sure if you google for how to override the default validation attributes, or how to write your own you'll find some sample code, they're fairly straight-forward.
|
|
|
|
|
Hi,
does anyone have a simple ASP.NET code snippet that accepts a internal Windows user name as a parameter and can retrieve the real name (first and last name) and the user group membership via LDAP?
Are there any spcial pre-requisites to implement this or
can this be done with built in ASP.NET means?
Thanks Dirk
|
|
|
|
|
|
Hi ,
Need to get the query string with values on button click with or with out using jquery .
like if my url is like this:
http://localhost:56121/Reports/ProjectScorecardByFilter?id=3" , here want to change the id value to 4 then click on button . In the controller method need to get the value of id as 4 .
|
|
|
|
|
Use the @Url.Action[^] method.
Using a hyperlink:
<a href="@Url.Action("ProjectScorecardByFilter", "Reports", new { id = 3 })">Link</a>
Using a form:
<form method="get" action="@Url.Action("ProjectScorecardByFilter", "Reports")">
<input type="hidden" name="id" value="3" />
<button type="submit">Button...</button>
</form>
Using jQuery:
<button data-link="@Url.Action("ProjectScorecardByFilter", "Reports", new { id = 3 })">JS Button...</button>
<script>
$(function(){
$(document).on("click", "button[data-link]", function(){
var href = this.getAttribute("data-link");
location.assign(href);
});
});
</script>
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I have an issue with my ASP.NET MVC4 application when I publish it to Azure. The roleManager part is not working and the application returns an error when it reaches to this code in my view:
bool isAdmin = User.IsInRole("admin");
And the error is the following:
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.
SQLExpress database file auto-creation error:
The connection string specifies a local Sql Server Express instance using a database location within the application's App_Data directory. The provider attempted to automatically create the application services database because the provider determined that the database does not exist. The following configuration requirements are necessary to successfully check for existence of the application services database and automatically create the application services database:
If the application is running on either Windows 7 or Windows Server 2008R2, special configuration steps are necessary to enable automatic creation of the provider database. Additional information is available at: http://go.microsoft.com/fwlink/?LinkId=160102. If the application's App_Data directory does not already exist, the web server account must have read and write access to the application's directory. This is necessary because the web server account will automatically create the App_Data directory if it does not already exist.
If the application's App_Data directory already exists, the web server account only requires read and write access to the application's App_Data directory. This is necessary because the web server account will attempt to verify that the Sql Server Express database already exists within the application's App_Data directory. Revoking read access on the App_Data directory from the web server account will prevent the provider from correctly determining if the Sql Server Express database already exists. This will cause an error when the provider attempts to create a duplicate of an already existing database. Write access is required because the web server account's credentials are used when creating the new database.
Sql Server Express must be installed on the machine.
The process identity for the web server account must have a local user profile. See the readme document for details on how to create a local user profile for both machine and domain accounts.
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:
[SqlException (0x80131904): 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)]
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling) +821
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +5771923
System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions) +38
System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +507
System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +154
System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +21
System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +90
System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +217
System.Data.SqlClient.SqlConnection.Open() +96
System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trusted, String connectionString) +75
[HttpException (0x80004005): Unable to connect to SQL Server database.]
System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trusted, String connectionString) +125
System.Web.Management.SqlServices.SetupApplicationServices(String server, String user, String password, Boolean trusted, String connectionString, String database, String dbFileName, SqlFeatures features, Boolean install) +89
System.Web.Management.SqlServices.Install(String database, String dbFileName, String connectionString) +29
System.Web.DataAccess.SqlConnectionHelper.CreateMdfFile(String fullFileName, String dataDir, String connectionString) +386
Interestingly in my local environment, it works fine, and it happens only in Azure.
For publishing to Azure I reconfigured the following properties in my web.config file as well, BUT I am still suspicious if I am missing some configuration somewhere else, since other parts of the application work fine such as login and registration:
Connection String:
<connectionStrings>
<!--<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-Portal.mdf;Initial Catalog=aspnet-Portal;Integrated Security=True" providerName="System.Data.SqlClient" />-->
<add name="DefaultConnection" connectionString="Data Source=tcp:***,1433;Initial Catalog=***;Persist Security Info=False;User ID=***;Password=***;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" providerName="System.Data.SqlClient" />
</connectionStrings>
And my Entity Framework configuration:
<entityFramework>
<!--<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">-->
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<!--<parameter value="mssqllocaldb" />-->
<parameter value="Data Source=Data Source=***,1433;Initial Catalog=***;Persist Security Info=False;User ID=***;Password=***;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
I Was wondering, if there is any other configuration which I need to modify for RoleManager in order to work in Azure?
Thank you for your time and consideration.
|
|
|
|
|
The error message was very descriptive and quite straight forward? It can't connect to SQL Express on the server using the connection string given. If SQL Express is not installed then no configuration or code changes are going to resolve that.
|
|
|
|
|
give me a latest project definition for last 1 year project..
|
|
|
|
|
Sorry, this site is not here to do your work.
|
|
|
|
|