Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug
Edit: Nevermind, figured out how to use Eval properly. It will do.

Dr. Poz fucked around with this message at 00:38 on Apr 23, 2007

Adbot
ADBOT LOVES YOU

Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug
I'm trying to build a level editor tool using XNA and currently my Editor form has a fairly neutered Game object as a field. Today however, I found this approach (expanded on here). I really like the approach because it seems natural that the form would be a component of a "Game" in this case, and allows you to use any Game Components you have already developed seamlessly with your editor.

However it has the big downside of the programmer having to either write winform code by hand, or copy it over from the "TemplateForm". This seems massively inefficient, and someone pointed out in the first comment that it was not necessary, but they didn't seem to expound on that much more. Can someone connect the dots for me on what the commenter might be trying to suggest?

Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug
Reposting this here because it's probably more applicable than in the general web development thread.

ASP.NET 2.0 - Membership/aspnetdb questions

So if I muck about in the aspnetdb and change the values of the UserName and LoweredUserName fields my web app stops being able to properly pull info from the database during that sessions, but if I log in everything begins to work properly again. I know I'm really not supposed to be editing the values contained in this field but this is just me playing around so I'm curious as to if this is a solvable problem.

Right now I simply have an override on the Login controls Authenticate method that uses the uses the users email address to grab the user name and authenticate the user instead of storing the email address as the actual user name. This allows me to change the login name whenever with impunity, so I was hoping to be able to use the user name as a kind of "display name" without having to create a table in aspnetdb. I have a few books on ASP.NET but none of them go deep on the database side of Membership. I'm not expecting an easy solution, but I always like to understand the problem better if anyone can provide details. At this point I'm thinking that the application can just log the user out but thats kind of sour.

Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug

pliable posted:

Okay that sounds good then. Fortunately for me, getting rid of the console I/O isn't a big issue, so hooray! Thanks.

I'm not sure if it is quite what you are looking for but there is a program called XYNTService that will run a specified .exe as a service. link

Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug
I have some controls that are status panels and they are programmatically added to my page. They are floated so that they can appear side by side. I wanted to put a border on the panel containing these controls but the floating throws that off, and since I cant put in a div declaratively for clearing, I created a custom control that is just a div used for clearing. It's really gimmicky but it works. My question is, am I stuck with this or is there a better way?

Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug
Edit: So I woke up this morning and I was a lot less stupid somehow. This is how I have it written now. Is there anything I could do better?

code:
(from r in Server.Responses where r.Time == (from t in Server.Responses select t.Time).Max() select r).Single<Response>();
I'm trying to pick up LINQ and am having difficulty googling up an example of what I'm trying to do. I have two tables (as shown below), one of servers, one of responses. I'm iterating through all of the servers but only need to access the most recent response. This is where I hit a wall.

I can do it by catching all of the responses in a List and sorting etc, but that would to be missing the point of the exercise. I'm still getting a hang of the different ways to select data, so different examples are welcome.

Only registered members can see post attachments!

Dr. Poz fucked around with this message at 16:51 on May 31, 2008

Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug
Have you run/developed any ASP.NET stuff prior to this? If not, did you just install IIS? If so, was it installed after the .NET Framework? If so, did you run %windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe? If not, do so.

Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug
If it wasn't included in your SQL Server install package, download and install SQL Management Studio Express. This will give you a decent database browser/query tool. If you didn't name the instance of SQL server that you installed, when you run the Management Studio for the Server name put in (local) and for Authentication choose Windows Authentication. This will allow you to log into the database under your Windows account rather than having to use a username/password combination.

You can configure it to allow remote connections but if its sole purpose is to serve data for web application run on the local machine then I would skip that entirely and recommend using Integrated Security for connecting to the database from your applications.

An example connection string in your case might be:
code:
<connectionStrings>
    <clear />
    <add name="MyConnectionString" connectionString="Data Source=(local);Initial Catalog=MyDB;Integrated Security=SSPI" providerName="System.Data.SqlClient" />
</connectionStrings>
And to ease things on yourself use
code:
ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString
as a way to statically access it. This way you only need to maintain and change one connection string should your requirements change.

Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug
I'm setting up a ClickOnce deployment site using Visual Studio 2008 and one of the prerequisites is SQL Server CE 3.5 w/SP1 but it doesn't appear in the list of prerequisite components from the Publish section of the main projects properties.

I currently have it set to get the requisite software from the Vendors website. Am I going to have to host the components myself to be able to include this?

Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug
Have you tried wrapping your "from" statement in parenthesis and calling .Single() on what is returned?

Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug

uXs posted:

In cases like this, I don't use the Linq query-like syntax, just the functions and the Lambda syntax:

code:
_feed = _db.BannerFeeds.Single(p => p.FeedID == feedID);

I would really recommend syntax like this and in fact was going to suggest it earlier but I didn't know what else you may have going on in your logic. Much cleaner and simpler. It's tough to get into the
code:
x  => x.Propery == whatever
habit but it quickly becomes second nature.

Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug

dwazegek posted:

We're currently using an MS SQL database together with linq-to-sql. Now my department head has got it in his head that customers shouldn't have to install SQL Server Express along with our product in order to run everything.

What he basically wants to do is use SQL server if it's available, and otherwise store everything (it's not that much data) in XML (either 1 giant file, or a series of smaller files).

I guess it would be possible to add a level of abstraction between the queries and the database, making it possible to replace the database with some sort of linq-to-xml mapping. However, I have literally zero experience with linq-to-xml, so I can't really be sure where potential problems might surface.

I'm pretty sure that this is a terrible idea, but he's pretty adamant. Is this idea even remotely possible?

My company was faced with a similar dilemma when we saw what deployment would be like with SQL Express and we opted to use Sql Server CE on the client side, though we routinely make rash decisions for sake of expediency (and they routinely come back to bite us in the rear end...) so YMMV.

Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug
I have a service that monitors a process on several servers and an ASP.NET web site that reports this information back. The service also has a RestartApp() method that the website can call to restart the monitored application.

My problem is this: The monitored application runs under a local admin account and the service runs under NetworkService. I can supply the proper credentials to start the process, but I seem to be unable to kill the process because NetworkService doesn't have permissions to kill a process running under this local admin account.

Is there a way to specify credentials to kill a process with? Is there a better service account to install the service under that would give me this ability?

I have a way or two to work around this, but they are less than ideal.
  1. Set the service to login under the local admin account. This means that if the local admin password (usually the same across all app specific servers) changes, I have to update the service log in as well. This is more work I would rather not do.
  2. Set the service to login under the local services (also a local admin) account. This account was created for situations similar to this one. Unfortunately I would have to still supply the credentials to start the process. Supplying the credentials means a password. Prompting the user for a password when requesting a restart is out of the question. Creating this service was a way around having to handout passwords in the first place. This leaves me with the options of hard coding the password (leading me to recompile the service if password ever changes) or storing it in a text file.

Any ideas?

Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug

CapnAndy posted:

I'm learning master pages (which are awesome). I know how to make a content page access variables from the master page -- how do you do it in reverse? If at all possible, I want the master page to assume a variable exists in the Main contentplaceholder and read it. It'll save me having to have every single page setting that variable.

Is there a reason you can't cache the variable in the session data instead?

Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug

Free Bees posted:

The only compatibility difference I know of is the use of custom user profile objects, specified in the web.config. Web Sites can take custom profile specifications in the web.config and compile them into a site-wide Profile class. Web Applications do not have this feature.

This is true by default but you do have the ability to roll your own wrapper around the ProfileBase class or use WebProfileBuilder. It's not quite as easy to set up as the homepage makes it seem, but it's still drat easy.

Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug
I'm using Visual Studio 2010 Beta 2 and whichever MVC preview is used by it. In my index view page I display a list of the users of the site with the names as links to a profile page. I also add an additional edit link next to the name of the current user browsing the page to allow the user to edit their profile. Obviously I want to restrict which profiles users can edit to only their own.

I've used the Authorize attribute to restrict access on the basis of roles, but can it be used in this fashion also or do I just write the logic into the controller action and have it return a default view?

Edit: I found a post on custom Authorization attributes. Would this be a use of them? http://davidhayden.com/blog/dave/archive/2009/04/09/CustomAuthorizationASPNETMVCFrameworkAuthorizeAttribute.aspx

Dr. Poz fucked around with this message at 19:43 on Nov 2, 2009

Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug
I'm using ASP.NET MVC in Visual Studio 2010 Beta 2 and I'm running into some strange behavior. In my master page, I link to a couple items in the head of the page like so:

code:
<link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../../Scripts/HandyTool/js/tool.js"></script>
<link href="../../Scripts/HandyTool/css/tool.css" rel="stylesheet" type="text/css" />
Everything works great when I run it locally but when I put it on a staging server (IIS 6.0 configured for MVC routing) the paths appear differently in different views. The paths appear perfectly fine just as above in my "Edit" view, but in my "Create" view they get cut down to this:

code:
<link href="../Content/Site.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../../Scripts/HandyTool/js/tool.js"></script>
<link href="../Scripts/HandyTool/css/tool.css" rel="stylesheet" type="text/css" />
Now, if I go to the url mysite.com/myapp/mycontroller/create/1 instead of mysite.com/myapp/mycontroller/create the paths show up perfectly. Is this a side effect of the changes I had to make to get IIS 6 to display MVC pages properly?

Dr. Poz fucked around with this message at 00:38 on Nov 13, 2009

Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug

wwb posted:


Excellent, this has worked out very well. Thanks!

Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug
Does uninstalling Silverlight take the local storage with it?

Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug
Is it bad form to use standard ASP.NET controls (such as the Menu control or something like it) in an ASP.NET MVC site?

Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug
I've been doing a lot of reading lately and seen several mentions to LINQ 2 SQL being more or less unofficially dropped in favor of the Entity Framework. Is this something thats been brewing at Microsoft or is this just blog chatter? I read some comparisons of the two technologies and was kind of left wondering where LINQ 2 SQL would fit in.

Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug
Silverlight question. I have a UserControl that looks like this:
code:
<UserControl>
[...]
	<Button x:Name="button" Style="{StaticResource MenuButton}" Height="42" Width="250">
		<Button.Content>
			<Grid VerticalAlignment="Bottom">
				<Grid.RowDefinitions>
					<RowDefinition Height="*" />
					<RowDefinition Height="42" />
				</Grid.RowDefinitions>
				<Grid.ColumnDefinitions>
					<ColumnDefinition />
				</Grid.ColumnDefinitions>
				<ListBox x:Name="MenuList" Style="{StaticResource MenuPanel}" Grid.Row="0" Grid.Column="0" Height="0">
					<HyperlinkButton Content="LINKY" />
				</ListBox>
				<TextBlock x:Name="MenuText" Style="{StaticResource MenuButtonText}" Text="Click" Grid.Row="1" Grid.Column="0">
				</TextBlock>
			</Grid>
		</Button.Content>
	</Button>	
</UserControl>
and a property in the code behind like this:
code:
public string Text { get; set; }
Now, I would think that I could just change my TextBlock Declaration to look more like this:
code:
<TextBlock Text="{Binding Text}"/>
but that doesn't seem to work. I can modify the properties getter/setter to directly set the TextBlock.Text property but then I don't get designer support. Am I taking the wrong approach to this?

Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug

fankey posted:

I think you're having the same issue the guy above was having. I haven't used Silverlight but the following would work in WPF
code:
<UserControl x:Name="_TheControl".....
 ...
  <TextBlock 
    x:Name="MenuText" 
    Style="{StaticResource MenuButtonText}" 
    Text="{Binding Path=Text, ElementName=_TheControl}" 
    Grid.Row="1" 
    Grid.Column="0">  

The problem definitely bears similarities but I'm not quite sure they are the same. I am trying to bind the property and not a member variable so that isn't a concern. I don't think I can assign a x:Name to the UserControl declaration. To be clear, its a definition for a UserControl and not an instance of one, I just left out some of the details that would make that more clear for the sake of brevity. When I do so, it yields this error:

code:
Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; FDM)
Timestamp: Mon, 4 Jan 2010 21:41:25 UTC


Message: Unhandled Error in Silverlight Application The name already exists in the tree: Ratshit. [Line: 0 Position: 0]   at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
   at AQMenu.MainPage.InitializeComponent()
   at AQMenu.MainPage..ctor()
   at AQMenu.App.Application_Startup(Object sender, StartupEventArgs e)
   at System.Windows.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
   at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)
Line: 1
Char: 1
Code: 0
URI: [url]http://localhost:22889/home/test[/url]
I know for a fact I don't have anything already named "Ratshit" in my application.

Dr. Poz fucked around with this message at 22:45 on Jan 4, 2010

Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug
I've found some pretty nice stuff here http://icons.mysitemyway.com/ also.

Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug

Triple Tech posted:

Derp, I'm confused. :saddowns: If I make one project for my DLL that will have code reused, and then make N many applications that use it, how do I refer to that DLL in my code? How do I deploy the DLL?

Deployment is hard. :eng99:

If you have the Project files, you can add the project to your solution and then in your application project, right click "References" > "Add Reference" and you can add the code library project. This will compile the project into a DLL and include it with your application. Otherwise, you can copy the your library DLL to any directory and add a reference to it in your application in the same way, just using the Browse tab of the Add Reference dialog instead of the Projects as you would in the other approach.

Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug
Working with ASP.NET MVC and I'm running into an odd problem with server side validation. In the controller action that handles a form post, ModelState.IsValid is always returning true. Even when I input absolutely no data and every property of my model is marked with the Required attribute. The only thing that I can think is that my use of Ajax.BeginForm doesn't play nice with validation.

Model
code:
    public class DemoRequest
    {        
        public DemoRequest()
        {
        }

        [DisplayName("Name: ")]
        [Required(ErrorMessage = "Name is required")]
        public string Name { get; set; }

        [DisplayName("Email: ")]
        [Email(ErrorMessage = "Not a valid email address")]
        [Required(ErrorMessage = "Email address required")]
        public string Email { get; set; }
        public string Company { get; set; }

        [DisplayName("Address: ")]
        [Required(ErrorMessage = "Address is required")]
        public string Address { get; set; }
 
        [DisplayName("Address2: ")]
        public string Address2 { get; set; }

        [DisplayName("City: ")]
        [Required(ErrorMessage = "City is required")]
        public string City { get; set; }

        [DisplayName("State: ")]
        [Required(ErrorMessage = "State is required")]
        public string State { get; set; }
        
        [DisplayName("Zip: ")]
        [ZipCode(ErrorMessage = "Not a valid zip code")]
        [Required(ErrorMessage = "Zip is required")]
        public string Zip { get; set; }

        [DisplayName("Company Type: ")]
        [Required(ErrorMessage = "Company type is required")]
        public string CompanyType { get; set; }
    }
View
code:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MySite.Models.DemoRequest>" %>
                        
    <% using (Ajax.BeginForm("RequestDemo", new AjaxOptions { UpdateTargetId = "DemoForm" }))
       { %>
        <div id="DemoForm" class="inputform">    
            <%= Html.LabelFor(d=>d.Name) %>
            <%= Html.TextBoxFor(d=>d.Name) %>
            <%= Html.ValidationMessageFor(d => d.Name) %>
            
            <%= Html.LabelFor(d=>d.Email) %>
            <%= Html.TextBoxFor(d => d.Email) %>
            <%= Html.ValidationMessageFor(d => d.Email) %>
            
            <%= Html.LabelFor(d=>d.Company) %>
            <%= Html.TextBoxFor(d => d.Company) %>
            <%= Html.ValidationMessageFor(d => d.Company) %>
            
            <%= Html.LabelFor(d => d.Address) %>
            <%= Html.TextBoxFor(d => d.Address) %>
            <%= Html.ValidationMessageFor(d => d.Address) %>
            
            <%= Html.LabelFor(d => d.Address2) %>
            <%= Html.TextBoxFor(d => d.Address2) %>
            <%= Html.ValidationMessageFor(d => d.Address2) %>
            
            <%= Html.LabelFor(d => d.City) %>
            <%= Html.TextBoxFor(d => d.City) %>
            <%= Html.ValidationMessageFor(d => d.City) %>
            
            <%= Html.LabelFor(d => d.State) %>
            <%= Html.TextBoxFor(d => d.State) %>
            <%= Html.ValidationMessageFor(d => d.State) %>
            
            <%= Html.LabelFor(d => d.Zip) %>
            <%= Html.TextBoxFor(d => d.Zip) %>
            <%= Html.ValidationMessageFor(d => d.Zip) %>
                                
            <%= Html.LabelFor(d => d.CompanyType)%>                    
            <%= Html.DropDownListFor(d=>d.CompanyType, 
                new List<SelectListItem>
                { 
                    new SelectListItem { Text="Type", Value="Type" },
                })
            %>                                                                              
            <button id="demoemailbutton" type="submit" value="Submit" title="Submit">Submit</button>                    
        </div>
    <% } %>  
Controller
code:
        public PartialViewResult RequestDemo(DemoRequest req)
        {
            if (ModelState.IsValid)
            {
                // do stuff
                return PartialView("ThankYouControl");
            }

            return PartialView("DemoRquestControl", req);

        }
No matter what ModelState.IsValid keeps coming back true, even when I don't fill out anything at all in the form.

Dr. Poz fucked around with this message at 21:33 on Jan 21, 2010

Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug
Fair enough. I'll side step the raging debate in the comments on that article, but this still leaves me with a quandry. I have (as seen in the model) a custom attribute called Email. It's a direct copy of one ScottGu posted in his blog. It's simply a regular expression that indicates whether or not something matches the pattern of an email address. I can input complete crap and ModelState.IsValid is true as always.

Here is the EmailAttribute just to be sure my idiocy doesn't lay here.
code:
    public class EmailAttribute : RegularExpressionAttribute
    {
        public EmailAttribute()
            : base(@"^[a-z0-9_\+-]+(\.[a-z0-9_\+-]+)*@[a-z0-9_\+-]+(\.[a-z0-9_\+-]+)*\.([a-z]{2,4})$") { }
    }

Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug

Begby posted:

I would like to be able to have a collection who's key is bound to a specific item property, but make it so the key changes if the value of the property changes, like so.

code:

SpecialCollection coll = new SpecialCollection<MyItem>();

MyItem itm1 = new MyItem();
itm1.Id = "taco";

// This should check to make sure the item key is unique
coll.add(itm1);

// Fetch the item based on its id
MyItem itm = coll["taco"];

itm.Id = "burrito";

// fetch it with the new key
MyItem itm = coll["burrito"];

Does something like that exist?

Can't you do this with LINQ to Collections .ToDictionary()?

Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug
I've run into some strange behavior I hope someone can explain. I have a web application that has uses LINQ 2 SQL and one of my tables contains latitude and longitude. In an attempt to make things easier on myself, I wrote a partial class extension to add a property that returns the latitude and longitude as a Microsoft.Maps.MapControl.Location object. The Location property appears under the web apps Class View, however when a Silverlight project in the same solution receives the collection of objects from the web service, the Location property does not exist.

This led me to look in the class view for the Silverlight project and the Location property does not appear there either. I've updated the service reference as well as removing it and readding the service but no dice. Why doesn't this property carry over?

Edit: I solved it by just moving the partial class to the Silverlight project since I don't really need it in the web app project anyways. Still, I'm curious about why it doesn't carry over.

Dr. Poz fucked around with this message at 20:57 on Feb 10, 2010

Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug
I'm using ASP.NET MVC 2 on Windows 2008 with IIS 7. I have a controller action that returns a filestream so that an image can be handed out somewhat dynamically. It looks like this:

code:
string path = Server.MapPath("/Content/img/bgs/");
string filename = "file.jpg";

return new FileStreamResult(new FileStream(Path.Combine(path, filename), FileMode.Open), "image/jpeg");
This all works great on my development machine, however when put into the Test server, this exception is thrown out:


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.UnauthorizedAccessException: Access to the path 'd:\sites\mysite\Content\img\bgs\file.jpg' is denied.

ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

To grant ASP.NET access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.


In an attempt to fix this I've given most associated user accounts read permissions but nothing seemed to work. I've given ASPNET, Network Service, LocalSystem and IUSR read persmissions individually (never all at once) and still the error is thrown. How can I make sure the application has the permissions it needs?

Dr. Poz fucked around with this message at 00:16 on Feb 23, 2010

Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug
I've simultaneously given the following accounts read permissions to the directory containing the files I'm seeking to dish out:

  • IUSR
  • Network Service
  • Internet Guest Account ({MachineName}\IUSR_{MachineName})
  • IIS_IUSRS
  • ASPNET

and the app still yields the exception. I realize this is a matter of configuration at this point but everything sensible that I have tried doesn't work. Is there something I should have added into the web.Config to enable an operation like this?

Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug

Sprawl posted:

Well this may tie into how you authentic into your system. Your login system do you do anything with the default login tools like.

code:
<%@ Page Language="VB" AutoEventWireup="True" %>
   <script runat="server" language="VB">
	
	Sub Page_Load(sender As Object, e As EventArgs)
	
	lblUser.Text = Page.User.Identity.Name
	lblWindow.Text = System.Security.Principal.WindowsIdentity.GetCurrent().Name
	lblThread.Text = System.Threading.Thread.CurrentPrincipal.Identity.Name
	
	
	End Sub
	
   </script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html  >
<head runat="server">
    <title>Test</title>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body> 
	<div id="content" >
	<form runat="server">	
		<table style="padding:50px">
			<tr>
				<td style="font-size:16pt;padding-top:25px"><asp:Label id="lblUser" runat="server" style="font-weight:bold" /></td>
				
			</tr>
			<tr>
				<td style="font-size:16pt;padding-top:25px"><asp:Label id="lblWindow" runat="server" style="font-weight:bold" /></td>
				
			</tr>
			<tr>
				<td style="font-size:16pt;padding-top:25px"><asp:Label id="lblThread" runat="server" style="font-weight:bold" /></td>
				
			</tr>
		</table> 
	</form>
	</div>
</body>
</html>
go throw this in a test.aspx and see if it punches out "System.Security.Principal.GenericPrincipal"
If its something different then your being a local user and they need perms iirc.

There was a configuration change I made this morning that for the life of me I can't remember. After I made the change though and refreshed the URL it dumped me to my sites login page. I'm sure this has some relevancy as it indicates that the issue IS tied into how the site authenticates. I'll give this a run. How can I find out the local user its running as if it pans out?


Sefyroth posted:

This might be a shot in the dark and maybe just fake code, but are you sure your path is fine? Server.MapPath("~/Content/img/bgs/") might work, I don't know how it resolves /.

The physical path that the error page gives me opens the file and works perfectly when I copy and paste it into a run prompt so I'm not so sure that's right.

Free Bees posted:

I had a weird permissions error returning files from an MVC app that was resolved magically by switching my app pool to the Classic pipeline.

Doing this causes a 404...interesting.

Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug

Sprawl posted:

Well if you know how to "do" mvc you can add that into a sister or a copy of that application and run that instead of trying to open the files its best to do these things "live". The labels and the setting in the page load sub are the only important part.

but if your "getting" a 404 error try this.

string path = Server.MapPath("/Content/img/bgs/");

to

string path = Server.MapPath("Content/img/bgs/");

The 404 only occurs when I change the AppPool managed pipeline from Integrated to Classic. Otherwise the exception that gets thrown does produce the correct physical path to the file it complains about not being able to access. Server.MapPath is resolving to the correct location. Edit: This all works beautifully on my development machine, this problem only occured when it was deployed.

Dr. Poz fucked around with this message at 20:34 on Feb 23, 2010

Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug
I appreciate everyones insight. Thankfully it is now resolved per the instructions of this blog post: http://codezest.com/archive/2009/12/14/system.unauthorizedaccessexception-access-to-the-path-is-denied.aspx

Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug
Is there really no info balloon/popup box in the Bing Maps Silverlight API? I've googled all to hell and I don't even see anything in the Pushpins about VisualStates.

Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug
I have an IDictionary<string, int> and I'm trying to assign values from a LINQ2SQL data source. I tried to assign to it like this:

code:
d = (from s in MyDataTable select new { s.StringText, s.id }).ToDictionary(s => s.StringText);
However I get this compile time error:

code:
Cannot implicitly convert type 'System.Collections.Generic.Dictionary<string,AnonymousType#1>' to 'System.Collections.Generic.IDictionary<string,int>'. An explicit conversion exists (are you missing a cast?)
If I put an explicit case like this:

code:
d = (IDictionary<string, int>)(from s in MyDataTable select new { s.StringText, s.id }).ToDictionary(s => s.StringText);
I get a similar run time blow up instead:

code:
Unable to cast object of type 'System.Collections.Generic.Dictionary`2[System.String,<>f__AnonymousType1`2[System.String,System.Int32]]' to type 'System.Collections.Generic.IDictionary`2[System.String,System.Int32]'.
What is the proper approach to get the data I need from my linq data source into an IDictionary<string, int>?

Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug
Having an issue in WPF. My application has two windows. One is for controlling a set of data and the other is for hosting a control to display the data. The problem is if the display form that contains the control isn't the Applications StartupUri, then the control doesn't render.

I can place basic WPF controls (ex: textblock) on the form and they will appear just fine. Is there some kind of initialization I'm failing to run on the form that is implicitly run when the form is set as the application StartupUri?

Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug

chocojosh posted:

Are you dynamically creating the hosted control in code behind, or is it declared in XAML?

If the control is being done in codebehind, you can try the following:

code:
FrameworkElement fe = ...;
fe.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
fe.Arrange(new Rect(new Point(0, 0), fe.DesiredSize));
fe.UpdateLayout();

Actually I solved this earlier today. It turns out it was because the resource dictionary containing the default style/template for the control wasn't "Themes/Generic.xaml".

Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug
WPF DataBinding question here. I have an object, Foo, and a custom control, FooDisplay, I want Foo bound to. When changes are made to Foo, I would like to see them reflected in FooDisplay with as little additional code written as possible. I'm really just learning WPF so if I'm going against the grain with any of my approaches, please feel free to point it out. I'm trying very hard to avoid picking up bad habits. Right now I have my app structured like this:

My Application class has a field of type Foo. I have a window for hosting FooDisplay and it has a DepenedencyProperty of Foos type. In my Application.OnStartup, I set this property to the instance of Foo that is created when App is. The only way I have been able to make the UI update as I make changes to Foo is by making individual properties of Foo into DependencyProperties. This seems like a "bad thing" though because it seems to be making a very tight coupling between my business objects and presentation code. Also, I dread the thought of making every property of it a DependencyProperty, even with the propdp shortcut. I'm trying to keep close to an MVC style doctrine to this and would appreciate any pointers on WPF application structure anyone may have.

Adbot
ADBOT LOVES YOU

Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug
I've been writing an ASP.NET MVC web application and have been trying to adhere to a lot of "best practices" like Localizing , using an IoC container and unit tests. I use the email address of a user to authenticate them. Given the fact that in the view, the HttpContext only has a reference to the users email address, is it a "Bad Thing©" to do something like the following from within a view?

code:
@(Membership.Provider as CustomMembershipService).GetUser(User.Identity.Name).DisplayName
I'm looking for a clean and consistent way to populate information about the current user on the screen and so far this is all I have. The only other option that comes to mind is to write a NonAction method to populate the ViewModel/ViewBag object with the data and call it from every controller action that returns a full view. Which of these approaches, if any, is passable and if none of them then what is a better approach?

  • Locked thread