I have ran into numerous problems running this application in a Medium Trust enviroment. I did come across a post addressing this issue however it was dealing with CSK 3.0 Beta1 .cs codebehind. The solution there was a modification to the SubSonic.dll
Could that be a solution for the CSK 2.0 .vb / Medium Trust issues? Otherwise, I believe its going to take a significant overhaul to get CSK 2.0 to run properly in a MT enviroment, especially for us "Code illiterate" people.
I'm attempting to use a SqlDataSource in lieu of existing code and I'm not having much success. Take a look at what I'm trying to do, perhaps there's a better way.
asp:Content
ID="Content1"
ContentPlaceHolderID="ContentPlaceHolder1"
runat="Server">
<div
id="Body">
<div
class="fullwidth">
<h2>
Add Blog Post</h2>
<p>
<asp:Label
ID="BlogDate"
runat="server"
Text="Blog Time Stamp:"></asp:Label>
<asp:Label
ID="TodayDate"
runat="server">
</asp:Label><strong><br
/><br
/>Blog Title<br
/>
<asp:TextBox
ID="txtTitle"
runat="server"
Width="640px">
</asp:TextBox></strong>
</p>
<p><strong>Blog
Text<br
/>
<asp:TextBox
ID="txtEntry"
runat="server"
Height="300px"
Width="640px"></asp:TextBox></strong>
</p>
<p>
<asp:Button
ID="add"
runat="server"
Text="Create New Blog"
/>
<asp:SqlDataSource
ID="SqlDataSource1"
runat="server"
ConnectionString="<%$ ConnectionStrings:MHSVB1ConnectionString %>"
OnSelecting="SqlDataSource1_Selecting"
SelectCommand="SELECT * FROM aspnet_membership(userID) WHERE (userID = @memid)"
InsertCommand="INSERT INTO BlogPosts(Title,
PostText, postdate, memid) VALUES (@Title,@PostText,@postdate,@memid)"
ProviderName="System.Data.SqlClient">
<InsertParameters>
<asp:ControlParameter
ControlID="txtTitle"
Name="Title"
PropertyName="Text"
/>
<asp:ControlParameter
ControlID="txtEntry"
Name="PostText"
PropertyName="Text"
/>
<asp:ControlParameter
ControlID="TodayDate"
Name="postdate"
PropertyName="Text"
/>
<asp:Parameter
Name="memid"
Type="Object"
/>
</InsertParameters>
</asp:SqlDataSource>
</p>
</div>
</div>
</asp:Content>
Code Behind:
Partial
Class Blogs_AddPost
Inherits System.Web.UI.Page
Protected
Sub Page_Load(ByVal sender
As
Object,
ByVal e
As System.EventArgs)
Handles
Me.Load
If User.IsInRole("Blogger") =
False
Then
Response.Redirect("~/blogs/default.aspx")
End
If
Session("FCKeditor:UserFilesPath") = Request.ApplicationPath.ToString &
"Files/"
TodayDate.Text = Date.Now
End
Sub
Protected
Sub SqlDataSource1_Selecting(ByVal sender
As
Object,
ByVal e
As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs)
Handles SqlDataSource1.Selecting
Dim currentUser
As MembershipUser = Membership.GetUser()
Dim currentUserId
As Guid =
CType(currentUser.ProviderUserKey, Guid)
e.Command.Parameters("@memid").Value = currentUserId
Response.Redirect("~/blogs/default.aspx")
End
Sub
Protected
Sub Add_Click(ByVal sender
As
Object,
ByVal e
As System.EventArgs)
Handles add.Click
SqlDataSource1.Insert()
End
Sub
End Class
As the current Source Code and Code Behind that I have posted here. When executed I receive the following error: 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: Implicit conversion from data type sql_variant to uniqueidentifier is not allowed. Use the CONVERT function to run this query.
Source Error:
Line 21:
Line 22: Protected Sub Add_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles add.Click
Line 23: SqlDataSource1.Insert()
Line 24: End Sub
Line 25: End Class
Source File: ~\blogs\AddPost.aspx.vb Line: 23
Stack Trace:
[SqlException (0x80131904): Implicit conversion from data type sql_variant to uniqueidentifier is not allowed. Use the CONVERT function to run this query.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +1948826
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4844747
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2392
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +204
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +954
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +162
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +175
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +137
System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand command, DataSourceOperation operation) +386
System.Web.UI.WebControls.SqlDataSourceView.ExecuteInsert(IDictionary values) +227
System.Web.UI.WebControls.SqlDataSource.Insert() +16
Blogs_AddPost.Add_Click(Object sender, EventArgs e) in ~\blogs\AddPost.aspx.vb:23
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053
I can add a DefaultValue to the InsertParameter [memid] and it will work all day long. However that's not the solution here.
<asp:Parameter
Name="memid"
DefaultValue="7bb2c179-65d9-45b2-b54a-b93371db50f0"
Type="String"
/>
I'm to the point of begging, would someone please offer some advise on how to correct this issue.
The corrections below will allow the Poll application to run in a Medium Trust enviroment. I have commented out the old source code so that it may be used as a reference. I've only posted the Subs & Functions that were affected.
Hope this helps someone out.
File Path: ~/AppCode/BLL/Poll.vb
Public
Shared
Sub Vote(ByVal pollId
As Guid,
ByVal answerId
As Guid,
ByVal userId
As Guid)
Using da
As PollVotesTableAdapter =
New PollVotesTableAdapter()
da.AddVote(Guid.NewGuid(), userId, answerId, DateTime.Now, pollId)
End
Using
'PollVotes.Insert(Guid.NewGuid(), userId, answerId, DateTime.Now, pollId)
End
Sub
Public
Shared
Sub AddPollReaction(ByVal reaction
As
String,
ByVal pollId
As Guid,
ByVal userId
As Guid)
Using da
As PollReactionsTableAdapter =
New PollReactionsTableAdapter()
da.AddReaction(Guid.NewGuid(), userId, DateTime.Now, reaction, pollId)
End
Using
'PollReactions.Insert(Guid.NewGuid(), userId, DateTime.Now, reaction, pollId)
End
Sub
Public
Shared
Sub DeleteReaction(ByVal reactionId
As Guid)
Using da
As PollReactionsTableAdapter =
New PollReactionsTableAdapter()
da.DeleteByReactionId(reactionId)
End
Using
'PollReactions.Delete(PollReactions.Columns.ReactionId, reactionId)
End
Sub
Public
Shared
Function GetAnswersForPollQuestion(ByVal pollQuestionId
As Guid)
As PollAnswersCollection
If pollQuestionId = Guid.Empty
Then
Return
Nothing
End
If
Dim rdr
As IDataReader = PollAnswers.FetchByParameter(PollAnswers.Columns.QuestionId, pollQuestionId)
Dim col
As
New PollAnswersCollection
col.LoadAndCloseReader(rdr)
Return col
'Dim dt As PollData.PollAnswersDataTable = New PollData.PollAnswersDataTable()
'Using da As PollAnswersTableAdapter = New PollAnswersTableAdapter()
'da.FillByQuestionId(dt, pollQuestionId)
'End Using
'Return dt
End
Function
Public
Shared
Function GetReactionsForPollQuestion(ByVal pollQuestionId
As Guid)
As PollReactionsCollection
If pollQuestionId = Guid.Empty
Then
Return
Nothing
End
If
Dim rdr
As IDataReader = PollReactions.FetchByParameter(PollReactions.Columns.PollId, pollQuestionId)
Dim col
As
New PollReactionsCollection
col.LoadAndCloseReader(rdr) Return col
'Dim dt As PollData.PollReactionsDataTable = New PollData.PollReactionsDataTable()
'Using da As PollReactionsTableAdapter = New PollReactionsTableAdapter()
'da.FillByPollId(dt, pollQuestionId)
'End Using
'Return dt
End
Function
hspreps
Member
6 Points
9 Posts
Problems and Solutions for running CSK 2.0 in a Medium Trust Enviroment
Feb 19, 2009 07:29 PM|LINK
I have ran into numerous problems running this application in a Medium Trust enviroment. I did come across a post addressing this issue however it was dealing with CSK 3.0 Beta1 .cs codebehind. The solution there was a modification to the SubSonic.dll
Could that be a solution for the CSK 2.0 .vb / Medium Trust issues? Otherwise, I believe its going to take a significant overhaul to get CSK 2.0 to run properly in a MT enviroment, especially for us "Code illiterate" people.
DJ
hspreps
Member
6 Points
9 Posts
Re: Problems and Solutions for running CSK 2.0 in a Medium Trust Enviroment
Feb 19, 2009 08:42 PM|LINK
Issue: Creating New Blogs
I'm attempting to use a SqlDataSource in lieu of existing code and I'm not having much success. Take a look at what I'm trying to do, perhaps there's a better way.
File Path: ~/Blogs/addPost.aspx
Source Code:<%
@ Page Title="" Language="VB" MasterPageFile="~/Default.master" AutoEventWireup="false"CodeFile="AddPost.aspx.vb" Inherits="Blogs_AddPost" %>
<
asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"><div id="Body">
<div class="fullwidth">
<h2>
Add Blog Post</h2>
<p>
<asp:Label ID="BlogDate" runat="server" Text="Blog Time Stamp:"></asp:Label>
<asp:Label ID="TodayDate" runat="server">
</asp:Label><strong><br /><br />Blog Title<br />
<asp:TextBox ID="txtTitle" runat="server" Width="640px"> </asp:TextBox></strong>
</p>
<p><strong>Blog Text<br />
<asp:TextBox ID="txtEntry" runat="server" Height="300px" Width="640px"></asp:TextBox></strong>
</p>
<p>
<asp:Button ID="add" runat="server" Text="Create New Blog" /> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MHSVB1ConnectionString %>"
OnSelecting="SqlDataSource1_Selecting"
SelectCommand="SELECT * FROM aspnet_membership(userID) WHERE (userID = @memid)"
InsertCommand="INSERT INTO BlogPosts(Title, PostText, postdate, memid) VALUES (@Title,@PostText,@postdate,@memid)"
ProviderName="System.Data.SqlClient"> <InsertParameters>
<asp:ControlParameter ControlID="txtTitle" Name="Title" PropertyName="Text" />
<asp:ControlParameter ControlID="txtEntry" Name="PostText" PropertyName="Text" />
<asp:ControlParameter ControlID="TodayDate" Name="postdate" PropertyName="Text" />
<asp:Parameter Name="memid" Type="Object" />
</InsertParameters>
</asp:SqlDataSource> </p>
</div>
</div>
</asp:Content> Code Behind:
Partial Class Blogs_AddPost
Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If User.IsInRole("Blogger") = False Then
Response.Redirect("~/blogs/default.aspx") End If Session("FCKeditor:UserFilesPath") = Request.ApplicationPath.ToString & "Files/"
TodayDate.Text = Date.Now End Sub Protected Sub SqlDataSource1_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles SqlDataSource1.Selecting Dim currentUser As MembershipUser = Membership.GetUser()
Dim currentUserId As Guid = CType(currentUser.ProviderUserKey, Guid)
e.Command.Parameters("@memid").Value = currentUserId Response.Redirect("~/blogs/default.aspx") End Sub Protected Sub Add_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles add.Click
SqlDataSource1.Insert() End Sub End Class
As the current Source Code and Code Behind that I have posted here. When executed I receive the following error:
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: Implicit conversion from data type sql_variant to uniqueidentifier is not allowed. Use the CONVERT function to run this query.
Source Error:
Source File: ~\blogs\AddPost.aspx.vb Line: 23
Stack Trace:
Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053
I can add a DefaultValue to the InsertParameter [memid] and it will work all day long. However that's not the solution here.
<asp:Parameter Name="memid" DefaultValue="7bb2c179-65d9-45b2-b54a-b93371db50f0" Type="String" /> I'm to the point of begging, would someone please offer some advise on how to correct this issue.hspreps
Member
6 Points
9 Posts
Re: Problems and Solutions for running CSK 2.0 in a Medium Trust Enviroment
Feb 21, 2009 08:17 PM|LINK
Issue: CSK 2.0 Blog - UNRESOLVED
Issue: CSK 2.0 Poll - SOLVED
The corrections below will allow the Poll application to run in a Medium Trust enviroment. I have commented out the old source code so that it may be used as a reference. I've only posted the Subs & Functions that were affected.
Hope this helps someone out.
File Path: ~/AppCode/BLL/Poll.vb
Public Shared Sub Vote(ByVal pollId As Guid, ByVal answerId As Guid, ByVal userId As Guid)Using da As PollVotesTableAdapter = New PollVotesTableAdapter()
da.AddVote(Guid.NewGuid(), userId, answerId, DateTime.Now, pollId) End Using 'PollVotes.Insert(Guid.NewGuid(), userId, answerId, DateTime.Now, pollId) End Sub Public Shared Sub AddPollReaction(ByVal reaction As String, ByVal pollId As Guid, ByVal userId As Guid)
Using da As PollReactionsTableAdapter = New PollReactionsTableAdapter()
da.AddReaction(Guid.NewGuid(), userId, DateTime.Now, reaction, pollId) End Using 'PollReactions.Insert(Guid.NewGuid(), userId, DateTime.Now, reaction, pollId) End Sub Public Shared Sub DeleteReaction(ByVal reactionId As Guid)
Using da As PollReactionsTableAdapter = New PollReactionsTableAdapter()
da.DeleteByReactionId(reactionId) End Using 'PollReactions.Delete(PollReactions.Columns.ReactionId, reactionId) End Sub Public Shared Function GetAnswersForPollQuestion(ByVal pollQuestionId As Guid) As PollAnswersCollection
If pollQuestionId = Guid.Empty Then
Return Nothing End If Dim rdr As IDataReader = PollAnswers.FetchByParameter(PollAnswers.Columns.QuestionId, pollQuestionId)
Dim col As New PollAnswersCollection
col.LoadAndCloseReader(rdr)
Return col 'Dim dt As PollData.PollAnswersDataTable = New PollData.PollAnswersDataTable() 'Using da As PollAnswersTableAdapter = New PollAnswersTableAdapter() 'da.FillByQuestionId(dt, pollQuestionId) 'End Using 'Return dt End Function Public Shared Function GetReactionsForPollQuestion(ByVal pollQuestionId As Guid) As PollReactionsCollection If pollQuestionId = Guid.Empty Then
Return Nothing End If Dim rdr As IDataReader = PollReactions.FetchByParameter(PollReactions.Columns.PollId, pollQuestionId)
Dim col As New PollReactionsCollection
col.LoadAndCloseReader(rdr) Return col 'Dim dt As PollData.PollReactionsDataTable = New PollData.PollReactionsDataTable() 'Using da As PollReactionsTableAdapter = New PollReactionsTableAdapter() 'da.FillByPollId(dt, pollQuestionId) 'End Using 'Return dt End Function