UrlEncode without HttpContext

by 25. August 2009 13:19

Yesterday I had to use the UrlEncode function.  UrlEncoding is used to converts all illegal characters in a URL to valid characters.  For example the space will be converted to %20.

Fortunately the .Net Framework supplies a UrlEncode method on its Server Class.  The server class resides in the HttpContext.  The problem is that you need a HttpContext Instance to call this class.

Using Reflector, I found out that the UrlEncode method on the Server Property uses the HttpUtility class.

image

So, instead of using this: HttpContext.Current.Server.UrlEncode(text)
you can also use: HttpUtility.UrlEncode(text)

The only thing to use this is to include the System.Web assembly in your project.

Tags: ,

Asp.Net

EXECUTE permission denied on object 'aspnet_CheckSchemaVersion', database 'myDB', schema 'dbo'.

by 7. April 2009 19:27

Problem

Today i launched the aspnet_regsql.exe.  Unfortunately i received the following error:

EXECUTE permission denied on object 'aspnet_CheckSchemaVersion', database 'myDB', schema 'dbo'.

Solution

Take the properties of the “NT Autority\Network Service” user.  Select the myDB database and add all the necessary Roles like aspnet_Membership_FullAccess to the user. 

image

In the screenshot are all the databaseroles added.

Tags:

Asp.Net | SQL

ASP.Net Membership API Cannot resolve collation conflict for equal to operation

by 31. December 2008 10:36

Error

I was using the ASP.NET SQL Server Setup Wizard (aspnet_regsql.exe) to deploy te database to the production SQL Server 2005.

image

Creation or change of the SQL Server database failed.

Setup failed.

Exception:
An error occurred during the execution of the SQL file 'InstallRoles.sql'. The SQL error number is 468 and the SqlException message is: Cannot resolve the collation conflict between "Latin1_General_CI_AS" and "SQL_Latin1_General_CP1_CI_AS" in the equal to operation.
[cut]

SQL file loaded:
InstallRoles.sql

Commands failed:

[cut] …  the failed SQL code

SQL Exception:
System.Data.SqlClient.SqlException: Cannot resolve the collation conflict between "Latin1_General_CI_AS" and "SQL_Latin1_General_CP1_CI_AS" in the equal to operation.
Cannot resolve the collation conflict between "Latin1_General_CI_AS" and "SQL_Latin1_General_CP1_CI_AS" in the equal to operation.
[cut
]…
Cannot resolve the collation conflict between "Latin1_General_CI_AS" and "SQL_Latin1_General_CP1_CI_AS" in the equal to operation.
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
   at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async)
   at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
   at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
   at System.Web.Management.SqlServices.ExecuteFile(String file, String server, String database, String dbFileName, SqlConnection connection, Boolean sessionState, Boolean isInstall, SessionStateType sessionStatetype)

Cause

Apparently this error happend when creating the asp.net membership stored procedures: aspnet_UsersInRoles_AddUsersToRoles or aspnet_UsersInRoles_RemoveUsersFromRoles.

The reason is pretty straithforward.

The aspnet_Roles table uses collation “latin1_General_CI_AS”.

image

While my database has a SQL_Latin1_General_CP1_CI_AS collation by default (just like my SQL server collation).

image

Solution

Use the SQL Profiler to get the Code of the of the Stored procedure which need to be created.  The SQL scripts of the ASP.Net Membership can also be found under: C:\Windows\Microsoft.NET\Framework\v2.0.50727  (InstallRoles.sql)

Change the line(s) in the scripts:

look for this line: DECLARE @tbNames table(Name nvarchar(256) NOT NULL PRIMARY KEY) and add the collation like specified in the “aspnet_Roles.RoleName” column.  Your new line should look like this:

DECLARE @tbNames table(Name nvarchar(256) COLLATE Latin1_General_CI_AS NOT NULL PRIMARY KEY)

You need to do this for the 2 stored procedures.

Tags:

Asp.Net | SQL

Asp.Net Debug (breakpoints) not working in VS2008

by 14. December 2008 11:42

Problem

I set a breakpoint and my debugger is not stopping at the breakpoint.  Debug is configured in the Web.Config:

<compilation debug="true">
    <assemblies>

My assembly is compliled in Debug mode: debug - any cpu

Solution

The last thing to check is of cource the Project Properties. 

Go to the tab “Web”, just below Signing.
image

You will see at the bottom a section Debuggers.
image

Activate the ASP.NET checkbox and your breakpoints will halt your running code again.

Microsoft support can be found here for some common problems: INFO Common Error When you Debug ASP.Net Applications in Visual Studio .NET and especially here: PRB: Visual Studio .NET Debugger Does Not Stop on Breakpoints When You Debug ASP.NET Pages

Tags: ,

Asp.Net | vs2008

Dynamic themes in ASP.NET 2.0 (C#)

by 22. March 2008 13:11

Today I looked at the ASP.NET 2.0 Themes.  I've been using them for a long time, but I never knew that you can set a default theme in the web.config.

Just add this to the system.web section

<pages styleSheetTheme="Black"/>

Further more I needed to change my theme dynamically.  I found an interesting article on this topic on CodeProject.

CodeProject: Dynamic themes in ASP.NET 2.0 (C#).

Tags: ,

Asp.Net

Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen