Jump to content
Xtreme .Net Talk

esteuart

Members
  • Posts

    11
  • Joined

  • Last visited

Personal Information

  • Occupation
    Programmer
  • Visual Studio .NET Version
    Enterprise Architect
  • .NET Preferred Language
    VB.NET

esteuart's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. Okay, that example is nearly word for word my code. The only difference is that I declare some variables and assign to them where MSDN does a lot of it inline. I still don't understand why mine doesn't work! Any suggestions?
  2. Will you please give me an example of how it should be? Keep in mind that I need to pass the role string into the cookie so that I can access it in the OnAuthenticate method to know which role to give the user. Thanks.
  3. Okay, well the code as you see is using a FormsAuthenticationTicket class. Shouldn't that work?
  4. I don't get it.... I have read about a hundred forums tonight, but this is the one that comes closest to my problem. I have never used roles before, but I understand their ability. I am trying to assign users who have admin rights (as defined by the DB) to an Admin role. I have to create a custom cookie so that I can set my role string when the user is authenticated. Here is the code: If Admin Then 'Admin Authenticated User Dim currentContext As HttpContext = HttpContext.Current Dim formsCookieStr As String = String.Empty Dim ticket As FormsAuthenticationTicket = New FormsAuthenticationTicket(1, tbUserName.Text, DateTime.Now, DateTime.Now.AddMinutes(30), False, "Admin") formsCookieStr = FormsAuthentication.Encrypt(ticket) Dim FormsCookie As New HttpCookie(FormsAuthentication.FormsCookieName, formsCookieStr) currentContext.Response.Cookies.Add(FormsCookie) Response.Redirect(FormsAuthentication.GetRedirectUrl(tbUserName.Text, False)) End If I got this code from another forum and it seems logical. The problem is that when the FormsAuthentication_OnAuthenticate function runs it doesn't recognize that there's anyone logged on! Here is the code: Public Sub FormsAuthentication_OnAuthenticate(ByVal source As Object, ByVal e As FormsAuthenticationEventArgs) If Not e.User Is Nothing Then If e.User.Identity.IsAuthenticated Then Dim id As FormsIdentity = e.User.Identity Dim ticket As FormsAuthenticationTicket = id.Ticket Dim roles() As String = {ticket.UserData} e.User = New System.Security.Principal.GenericPrincipal(e.User.Identity, roles) End If End If End Sub When it checks e.User, it is nothing, and therefore there is nothing to get the identity from. The weirdest part is that after it doesn't do anything in this function, the user is still authenticated (I know this because I have set a response.write() that tells me whether or not the user has been authenticated. But, the user is still not part of the role. Please help!!!:eek:
  5. It seems to me that all you need to do is onLoad loop through the tree like you do when apply is clicked, only instead of setting the registry, read from the registry. If the keys are there and the values are not deleted, then they are enabled.
  6. I need my stand-alone application to both read and write to the registry. I have no problems reading from the registry, but whenever I try to save my keys to the registry I get the following error: An unhandled exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll Additional information: Cannot write to the registry key. I assume it has something to do with security permissions - I don't know. If it is a security issue, how do I give my application permission to update the registry? Here is the code Private key As Microsoft.Win32.RegistryKey Private Const KEY_LOCATION = "Software\Company\Product" Public Sub New() key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(KEY_LOCATION) End Sub Private Sub frmService_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load tbBroadcast.Text = key.GetValue("Broadcast", "") tbBgPath.Text = key.GetValue("InstallLocation", "") nudTimer.Value = key.GetValue("TimerLength", 10) End Sub Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click key.SetValue("Broadcast", tbBroadcast.Text) key.SetValue("InstallLocation", tbBgPath.Text) key.SetValue("TimerLength", nudTimer.Value) End Sub The program dies on key.SetValue("Broadcast", tbBroadcast.Text). Please help!
  7. I have figured out the problem... In order to use TableStyles, a TableMapping object must be created. When defined statically at design-time, the IDE creates the TableMapping for you. So, when you do things dynamically, you must create the TableMapping yourself. I will post the new code below. NOTE: The ad.ExecSQL function is one that I wrote to abstract the connection to the database. The old one from the previous message sent in the SQL statement and the dataset. The new one sends in the SQL statement, the dataset, and the TableMapping. The table mapping must be added to the DataAdapter.TableMappings collection. This is all done behind the scenes in this code. 'This code is to hide a column in a datagrid using dynamic connections to the database. Dim ts As New DataGridTableStyle(True) Dim DsAccounts As New Dataset() Dim tm As New System.Data.Common.DataTableMapping("Table", "GBSAccounts") 'Table mappings are required in order to get the table styles to work. The table mapping above uses 'these column mappings. tm.ColumnMappings.Add("GroupNo", "GroupNo") tm.ColumnMappings.Add("Organization", "Organization") tm.ColumnMappings.Add("ID", "ID") ad.ExecSQL("Select GroupNo, Organization, Id from GBS.dbo.GBSAccounts", DsAccounts, tm) 'Optional way of hiding a column at the dataset level... 'DsAccounts.Tables(0).Columns("ID").ColumnMapping = MappingType.Hidden dgAccounts.DataSource = DsAccounts.Tables(0) 'Alter the styles of the columns. ts.MappingName = "GBSAccounts" dgAccounts.TableStyles.Add(ts) dgAccounts.TableStyles("GBSAccounts").GridColumnStyles(2).Width = 0
  8. My problem is that the GridColumnStyles collection is not getting created like it should when a datasource is selected for the datagrid. I get an out of range error. I had the following code working just fine when the form used static databinding at design-time. Since I changed the code to use a dataset acquired on the fly, the code has stopped working. I don't know if it is a difference between using the components or not, or if I'm just doing something wrong. I have read all the helps I can find, and nothing seems to be wrong except that it doesn't work. Here is the offending code: Dim ts As New DataGridTableStyle(False) Dim DsAccounts as new Dataset() ad.ExecSQL("Select GroupNo, Organization, Id from GBS.dbo.GBSAccounts", DsAccounts) dgAccounts.DataSource = DsAccounts.Tables(0) ts.MappingName = "GBSAccounts" dgAccounts.TableStyles.Add(ts) dgAccounts.TableStyles("GBSAccounts").GridColumnStyles(2).Width = 0
  9. Right now I'm working on the screen version, but it will be going out to a printer in the end. I'm glad to hear that there is a way to make it accurate for printing as this is a must. Someone on another forum gave me some code that does a pretty good job of figuring the size for the screen. It isn't accurate, but it will work for my purposes. I will post the code below. The problem with it is when I change my resolution, it isn't very accurate at all, but like I said, it will work. Here's the code: rect.Width = (Graphics.DpiX / MM_PER_INCH) * RECT_WIDTH_IN_MM rect.Height = (Graphics.DpiY / MM_PER_INCH) * RECT_HEIGHT_IN_MM rect.Location = New Point((Panel.Width - rect.Width) / 2, (Panel.Height - rect.Height) / 2) MM_PER_INCH is a constant of 25.4F. It is the number of Millimeters in an Inch. The other constants are the actual size of the Rectangle. Thanks for your help, Eric
  10. I understand that there is no FIXED value and that it is monitor and resolution dependent. That, in fact, is my problem. I want the rectangle that I draw (using GDI+ in VB.NET) to be actual size no matter what the resolution or monitor size is. I need a way to calculate what the size SHOULD be in pixels based on the actual size in Millimeters. The graphics class will let me change the unit to Millimeters and then when I draw the rectangle it is the right size. The problem is then I need to center it in a Panel (a VB component). The panel is defined in Pixels, so I can't figure out where the top left corner of the rectangle should be. The top-left corner is based on the following equation: PanelWidth / 2 - RectangleWidth / 2 and PanelHeight / 2 - RectangleHeight / 2. This will give me the left and top points, respectively. The problem is that the rectangle is in Millimeters and the Panel is in Pixels, so the math won't work. Therefore I need to convert one or the other to the same unit of measure so that I can make the above equation work. I should note that this needs to be dynamic because this application could be run on various monitors and resolutions. Any suggestions? Eric
  11. I need to draw a rectangle exactly in the middle of a panel. I know the exact size of the rectangle, in Millimeters, that I need, and I can figure out the size of the panel in pixels. I need to convert the millimeters to pixels so that I can figure the Location for the rectangle. Does anyone know how to convert from Millimeters to pixels based on the current resolution??:confused:
×
×
  • Create New...